#include <cstdio>
#include <algorithm>
using namespace std;

const int N = 2000 + 1;
const int inf = (int) 1e9;
int n, k, x[N], l[2], r[2], res[N], ans[N][N];
pair<int, int> par[N][N];

void relax_min(int& a, int b) {
	a = min(a, b);
}

bool in_range(int x, int l, int r) {
	return (l <= x) && (x <= r);
}

int main() {
	freopen("dynasties.in", "r", stdin);
	freopen("dynasties.out", "w", stdout);
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
		scanf("%d", &x[i]);
	scanf("%d", &k);
	int optimal = inf, optimal_test = -1;
	for (int it = 0; it < k; ++it) {
		for (int t = 0; t < 2; ++t)
			scanf("%d%d", &l[t], &r[t]);
		for (int i = 0; i <= n; ++i)
			for (int j = 0; j <= n; ++j)
				ans[i][j] = inf + 1;
		ans[0][0] = 0;
		int best = inf;
		pair<int, int> best_pos = make_pair(-1, -1);
		for (int i = 0; i <= n; ++i)
			for (int j = 0; j <= n; ++j) {
				if ((i == 0) || in_range(x[max(i, j)] - x[i - 1], l[0], r[0])) {
					int value = ans[i][j] + (int) (i == max(i, j));
					if (ans[max(i, j) + 1][j] > value) {
						ans[max(i, j) + 1][j] = value;
						par[max(i, j) + 1][j] = make_pair(i, j);
					}
				}
				if ((j == 0) || in_range(x[max(i, j)] - x[j - 1], l[1], r[1])) {
					int value = ans[i][j] + (int) (j == max(i, j));
					if (ans[i][max(i, j) + 1] > value) {
						ans[i][max(i, j) + 1] = value;
						par[i][max(i, j) + 1] = make_pair(i, j);
					}
				}
				if (((i == n) || (j == n)) && (best > ans[i][j] - 1)) {
					best = ans[i][j] - 1;
					best_pos = make_pair(i, j);
				}
			}
		if (best < optimal) {
			optimal = best;
			optimal_test = it + 1;
			while ((best_pos.first > 0) || (best_pos.second > 0)) {
				pair<int, int> parent = par[best_pos.first][best_pos.second];
				for (int i = parent.first; i < best_pos.first; ++i)
					res[i] = 0;
				for (int i = parent.second; i < best_pos.second; ++i)
					res[i] = 1;
				best_pos = parent;
			}
		}
	}
	if (optimal < inf) {
		printf("%d %d\n", optimal_test, optimal);
		for (int i = 0; i < n; ++i)
			printf("%d", res[i] + 1);
		printf("\n");
	} else
		printf("0\n");
	return 0;
}