#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>
#include <deque>

using namespace std;

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

const int maxK = 101;
const int size = 3 * 1000 + 10;
const int inf = 1000 * 1000 * 1000;

int dist[size][size];
int ansvec[maxK][size];
pair <int, int> from[size][size];
int lb[2][maxK], rb[2][maxK];
int n, k;
int age[size];

inline int getcost(int h, int tp, int p1, int p2) {
    if (p1 == 0)
        return 0;
    if (p2 == n + 1)
        return 0;
    if (age[p2 - 1] - age[p1 - 1] < lb[tp][h] || age[p2 - 1] - age[p1 - 1] > rb[tp][h])
        return -1;
    return (p1 + 1 == p2);
}

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);
    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 ans = n + 1;
    int ansK = -1;
    for (int h = 0; h < k; h++) {
        for (int i = 0; i <= n + 1; i++)
            for (int j = 0; j <= n + 1; j++)
                dist[i][j] = inf;
        dist[0][0] = 0;

        deque <pair <int, int> > deq;
        deq.push_back(mp(0, 0));
        pair <int, int> v;
        int cst, mx;
        while (!deq.empty()) {
            v = deq.front();
            //cerr << v.fs << ' ' << v.sc << ' ' << dist[v.fs][v.sc] << ' ' << from[v.fs][v.sc].fs << ' ' << from[v.fs][v.sc].sc << endl;
            mx = max(v.fs, v.sc);
            deq.pop_front();

            if (v.fs == n || v.sc == n) {
                dist[n + 1][n + 1] = dist[v.fs][v.sc];
                from[n + 1][n + 1] = v;
                break;
            }

            if (v.fs < n) {
                cst = getcost(h, 0, v.fs, mx + 1);
                if (cst != -1 && dist[mx + 1][v.sc] + cst > dist[v.fs][v.sc] + cst) {
                    dist[mx + 1][v.sc] = dist[v.fs][v.sc] + cst;
                    from[mx + 1][v.sc] = v;
                    if (cst == 0) {
                        deq.push_front(mp(mx + 1, v.sc));
                    } else {
                        deq.push_back(mp(mx + 1, v.sc));
                    }
                }
            }
            if (v.sc < n) {
                cst = getcost(h, 1, v.sc, mx + 1);
                if (cst != -1 && dist[v.fs][mx + 1] + cst > dist[v.fs][v.sc] + cst) {
                    dist[v.fs][mx + 1] = dist[v.fs][v.sc] + cst;
                    from[v.fs][mx + 1] = v;
                    if (cst == 0) {
                        deq.push_front(mp(v.fs, mx + 1));
                    } else {
                        deq.push_back(mp(v.fs, mx + 1));
                    }
                }
            }
        }

        if (dist[n + 1][n + 1] < inf) {
            pair <int, int> p = mp(n + 1, n + 1);
            while (p.fs != 0 || p.sc != 0) {
                //cerr << p.fs << ' ' << p.sc << endl;
                ansvec[h][max(p.fs, p.sc) - 1] = (p.sc == max(p.fs, p.sc));
                p = from[p.fs][p.sc];
            }
        }

        if (dist[n + 1][n + 1] < ans) {
            ans = dist[n + 1][n + 1];
            ansK = h;
        }
    }

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

    return 0;
}
