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

const int N = 20;
const int inf = (int) 1e9;
int n, k, x[N], l[2], r[2], res[N];

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]);
		int best = inf, best_mask = -1;
		for (int mask = 0; mask < (1 << n); ++mask) {
			bool ok = true;
			int res = -1, last[2] = {-1, -1};
			for (int i = 0; i < n; ++i) {
				int bit = (mask >> i) & 1;
				if ((last[bit] != -1) && !in_range(x[i] - x[last[bit]], l[bit], r[bit])) {
					ok = false;
					break;
				}
				res += (int) (last[bit] == i - 1);
				last[bit] = i;
			}
			if (ok && (best > res)) {
				best = res;
				best_mask = mask;
			}
		}
		if (best < optimal) {
			optimal = best;
			optimal_test = it + 1;
			for (int i = 0; i < n; ++i)
				res[i] = (best_mask >> i) & 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;
}