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

const int N = (int) 2e5 + 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 = 0, 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 = 0, best_pos = -1, best_t = -1, start[2] = {0, 0}, finish[2] = {0, 0}, 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]++;
		}
		deque< pair<int, int> > dq[2];
		for (int i = 1; i < n; ++i)
			for (int t = 0; t < 2; ++t) {
				ans[t][i] = (first[t ^ 1] >= i - 1) ? 1 : -inf;
				p[t][i] = 0;
				if ((i >= 2) && !in_range(x[i - 1] - x[i - 2], l[t ^ 1], r[t ^ 1])) {
					dq[t].clear();
					start[t] = i - 1, finish[t] = i - 2;
				}
				while ((finish[t] + 1 < i) && (x[i] - x[finish[t]] >= l[t])) {
					finish[t]++;
					int value = ans[t ^ 1][finish[t]];
					while (!dq[t].empty() && (dq[t].back().first < value))
						dq[t].pop_back();
					dq[t].push_back(make_pair(value, finish[t]));
				}
				while ((start[t] < i) && (x[i] - x[start[t] - 1] > r[t])) {
					if (!dq[t].empty() && (dq[t].front().second == start[t]))
						dq[t].pop_front();
					start[t]++;
				}
				if (!dq[t].empty() && (ans[t][i] < dq[t].front().first + 1)) {
					ans[t][i] = dq[t].front().first + 1;
					p[t][i] = dq[t].front().second;
				}
				if ((best < ans[t][i]) && (i >= last[t])) {
					best = ans[t][i];
					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 != 0) {
		printf("%d %d\n", optimal_test, n - 1 - optimal);
		for (int i = 0; i < n; ++i)
			printf("%d", res[i] + 1);
		printf("\n");
	} else
		printf("0\n");
	return 0;
}