#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 = 200 * 1000 + 10;
const int maxK = 50;
const int rms = (1 << 19) - 1;
const int hrms = rms / 2;
const int inf = 1000 * 1000 * 1000;

int n;
int year[size];
int lb[2][maxK];
int rb[2][maxK];
int rmq[2][rms];
bool good[2][size];
int sum[2][size];
int ans[2][size];
int from[2][size];
int rans[size];

inline pair <int, int> getsegment(int h, int tp, int ps) {
    int L = lower_bound(year, year + n + 1, year[ps] - rb[tp][h]) - year;
    int R = lower_bound(year, year + n + 1, year[ps] - lb[tp][h]) - year;
    if (year[ps] - lb[tp][h] < year[R])
        R--;
    if (L == 1)
        L--;
    return mp(L, R);
}

int leftgood(int tp, int ps) {
    int lb = 0, rb = ps;
    int mid;
    while (lb < rb) {
        mid = (lb + rb) / 2;
        //cerr << "comp " << sum[ps] << ' ' << sum[mid] << ' ' << ps - mid << endl;
        if (sum[tp][ps] - sum[tp][mid] == ps - mid)
            rb = mid;
        else
            lb = mid + 1;
    }

    return lb;
}

int rss(int tp, int v, int lb, int rb, int i, int j) {
    if (lb > j || rb < i)
        return -1;
    if (lb >= i && rb <= j)
        return rmq[tp][v];
    int a1 = rss(tp, v * 2, lb, lb + (rb - lb) / 2, i, j);
    int a2 = rss(tp, v * 2 + 1, lb + (rb - lb) / 2 + 1, rb, i, j);
    //cerr << lb << ' ' << rb << ' ' << a1 << ' ' << a2 << endl;
    if (a1 == -1)
        return a2;
    else
        if (a2 == -1)
            return a1;
        else
            if (ans[tp][a1] > ans[tp][a2])
                return a1;
            else
                return a2;
}

void change(int tp, int ps) {
    int v = ps + hrms + 1;
    rmq[tp][v] = ps;
    while (v > 1) {
        v /= 2;
        if (ans[tp][rmq[tp][v * 2]] > ans[tp][rmq[tp][v * 2 + 1]])
            rmq[tp][v] = rmq[tp][v * 2];
        else
            rmq[tp][v] = rmq[tp][v * 2 + 1];
    }
}

int process(int s) {
    for (int i = 1; i <= n; i++)
        for (int j = 0; j < 2; j++) {
            good[j][i] = (year[i] - year[i - 1] >= lb[j][s] && year[i] - year[i - 1] <= rb[j][s]);
            //cerr << good[i][j] << endl;
            if (i == 1)
                good[j][i] = true;
            sum[j][i] = sum[j][i - 1] + good[j][i];
        }
    for (int i = 0; i < rms; i++) {
        rmq[0][i] = 0;
        rmq[1][i] = 0;
    }
    ans[0][0] = 0;
    ans[1][0] = 0;
    ans[0][1] = 0;
    ans[1][1] = 0;
    change(0, 0);
    change(1, 0);
    change(0, 1);
    change(1, 1);
    for (int i = 2; i <= n; i++) {
        for (int j = 0; j < 2; j++) {
            pair <int, int> v = getsegment(s, j, i);
            v.fs++, v.sc++;
            //cerr << "seq1 " << v.fs << ' ' << v.sc;
            v.fs = max(v.fs, leftgood(j ^ 1, i - 1));
            v.sc = min(v.sc, i - 1);
            //cerr << " seg " << j << ' ' << i << ' ' << v.fs << ' ' << v.sc << endl;

            ans[j][i] = -1;
            if (v.fs <= v.sc) {
                from[j][i] = rss(j ^ 1, 1, 1, hrms + 1, v.fs + 1, v.sc + 1);
                ans[j][i] = ans[j ^ 1][from[j][i]] + 1;
            }
            if (leftgood(j ^ 1, i - 1) == 0 && ans[j][i] < 1) {
                ans[j][i] = 1;
                from[j][i] = 0;
            }
            if (ans[j][i] < 0) {
                from[j][i] = -1;
                ans[j][i] = -inf;
            }
            change(j, i);

            //cerr << j << ' ' << i << ' ' << ans[j][i] << ' ' << from[j][i] << endl;
        }
    }
    int mx = -inf;
    for (int i = leftgood(0, n); i <= n; i++)
        mx = max(mx, ans[0][i]);
    for (int i = leftgood(1, n); i <= n; i++)
        mx = max(mx, ans[1][i]);

    if (mx < 0)
        return -1;
    else
        return n - 1 - mx;
}

void restore_path(int tp, int ps, int lst) {
    for (int i = max(1, ps); i < lst; i++)
        rans[i - 1] = tp;
    if (ps == 0)
        return;
    restore_path(tp ^ 1, from[tp][ps], ps);
}

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

    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%d", &year[i + 1]);
    year[0] = -inf;

    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 ansK = -1, av = n + 1;
    for (int i = 0; i < k; i++) {
        int la = process(i);
        if (la != -1 && la < av) {
            av = la;
            ansK = i;
        }
    }

    if (ansK == -1)
        printf("0\n");
    else {
        process(ansK);
        printf("%d %d\n", ansK + 1, av);
        bool flag = false;
        for (int i = leftgood(0, n); i <= n; i++)
            if (!flag && ans[0][i] == n - 1 - av) {
                restore_path(0, i, n + 1);
                flag = true;
            }
        for (int i = leftgood(1, n); i <= n; i++)
            if (!flag && ans[1][i] == n - 1 - av) {
                restore_path(1, i, n + 1);
                flag = true;
            }
        for (int i = 0; i < n; i++)
            printf("%c", char('1' + rans[i]));
        printf("\n");
    }

    return 0;
}
