#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 * 1000 + 100;
const int maxK = 101;

int n, k;
int ansvec[maxK][size];
int lb[2][maxK];
int rb[2][maxK];
int curvec[2][size];
int age[size];

int buildAns(int fs, int L1, int R1, int L2, int R2) {
    curvec[fs][0] = fs;
    int lst1 = -1, lst2 = -1;
    if (fs == 0)
        lst1 = 0;
    else
        lst2 = 0;

    for (int i = 1; i < n; i++) {
        bool could1 = (lst1 == -1 || (age[i] - age[lst1] >= L1 && age[i] - age[lst1] <= R1));
        bool could2 = (lst2 == -1 || (age[i] - age[lst2] >= L2 && age[i] - age[lst2] <= R2));

        if (!could1 && !could2)
            return -1;
        if (could1 && !could2) {
            curvec[fs][i] = 0;
            lst1 = i;
        }
        if (could2 && !could1) {
            curvec[fs][i] = 1;
            lst2 = i;
        }
        if (could1 && could2) {
            curvec[fs][i] = curvec[fs][i - 1] ^ 1;
            if (curvec[fs][i] == 0)
                lst1 = i;
            else
                lst2 = i;
        }
    }

    int cnt = 0;
    for (int i = 1; i < n; i++)
        cnt += (curvec[fs][i] == curvec[fs][i - 1]);

    return cnt;
}

int main()
{
    freopen("dynasties.in", "r", stdin);
	freopen("dynasties.out", "w", stdout);
	
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%d", &age[i]);
    scanf("%d", &k);
    int ans = n + 1;
    int ansK = -1;
    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 cur[2];
        for (int j = 0; j < 2; j++)
            cur[j] = buildAns(j, lb[0][i], rb[0][i], lb[1][i], rb[1][i]);
        int sw = (cur[0] == -1 || (cur[1] != -1 && cur[1] < cur[0]));
        //cerr << sw << ' ' << cur[0] << ' ' << cur[1] << endl;
        if (cur[sw] != -1 && cur[sw] < ans) {
            ans = cur[sw];
            ansK = i + 1;
        }
        for (int j = 0; j < n; j++)
            ansvec[i][j] = curvec[sw][j];
    }

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

    return 0;
}
