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

const int N = 10000 + 1;
const int inf = (int) 1e9;
int n, k, x[N], l[2], r[2], ans[2][N], p[2][N], res[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]);
		ans[0][0] = ans[1][0] = 0;
		int best = inf, best_pos = -1, best_t = -1, first[2] = {0, 0}, last[2] = {n - 1, n - 1};
		for (int t = 0; t < 2; ++t) {
			while ((last[t] > 0) && in_range(x[last[t]] - x[last[t] - 1], l[t], r[t]))
				last[t]--;
			while ((first[t] + 1 < n) && in_range(x[first[t] + 1] - x[first[t]], l[t], r[t]))
				first[t]++;
		}
		for (int i = 1; i < n; ++i)
			for (int t = 0; t < 2; ++t) {
				ans[t][i] = (i - 1 <= first[t ^ 1]) ? i - 1 : inf;
				p[t][i] = 0;
				for (int j = i - 1; j >= 1; --j) {
					if ((j < i - 1) && !in_range(x[j + 1] - x[j], l[t ^ 1], r[t ^ 1]))
						break;
					if (in_range(x[i] - x[j - 1], l[t], r[t])) {
						int value = ans[t ^ 1][j] + i - j - 1;
						if (ans[t][i] > value) {
							ans[t][i] = value;
							p[t][i] = j;
						}
					}
				}
				if ((best > ans[t][i] + n - i - 1) && (i >= last[t])) {
					best = ans[t][i] + n - i - 1;
					best_t = t;
					best_pos = i;
				}
			}
		if (best < optimal) {
			optimal = best;
			optimal_test = it + 1;
			best_t ^= 1;
			p[best_t][n] = best_pos;
			best_pos = n;
			while (best_pos > 0) {
				for (int i = p[best_t][best_pos]; i < best_pos; ++i)
					res[i] = best_t ^ 1;
				best_pos = p[best_t][best_pos];
				best_t ^= 1;
			}
		}
	}
	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;
}