#pragma comment(linker, "/STACK:1000000000")
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <string.h>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define PI 3.1415926535897932384626433832795

const int size = 100;
int age[size];
int cur[size];

int lb[2][size], rb[2][size];

int main()
{
    freopen("dynasties.in", "r", stdin);
	freopen("dynasties.out", "w", stdout);
    int n, k;

    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%d", &age[i]);
    scanf("%d", &k);
    for (int i = 0; i < k; i++)
        scanf("%d%d%d%d", &lb[0][i], &rb[0][i], &lb[1][i], &rb[1][i]);

    int ansvec = -1, ans = n + 1, ansK = -1;
    for (int h = 0; h < k; h++) {
        for (int i = 0; i < (1 << n); i++) {
            int lst[2], cur, cnt = 0;
            lst[0] = lst[1] = -1;
            bool flag = true;
            for (int j = 0; j < n; j++) {
                cur = (i >> j) & 1;
                cnt += (lst[cur] != -1 && lst[cur] == j - 1);
                if (lst[cur] != -1 && (age[j] - age[lst[cur]] < lb[cur][h] || age[j] - age[lst[cur]] > rb[cur][h])) {
                    flag = false;
                    break;
                }
                lst[cur] = j;
            }
            if (flag && cnt < ans) {
                ans = cnt;
                ansK = h + 1;
                ansvec = i;
            }
        }
    }

    if (ansvec == -1)
        printf("0\n");
    else {
        printf("%d %d\n", ansK, ans);
        for (int j = 0; j < n; j++)
            printf("%c", char('1' + ((ansvec >> j) & 1)));
        printf("\n");
    }

    return 0;
}
