big = 1 000 000
s = 0
S = []
unseen = 0
seen(v) = if (v < big, bittest(s, v), setsearch(S, v))
see(v) = if (v < big, s = bitor(s, 2^v), S = setunion(S, [v])); while (seen(unseen), unseen++)

other(k) = {
	while (1,
		my (v = bitor(h[k], e[k]));
		if (seen(v),
				e[k]++,
				return (v)
		);
	);
}

{
	print ("0 0");
	a = vector(10 000);
	u = 1;
	h = vector(200);	\\ h(n) = A365232(n, 0)
	e = vector(#h);
	m = -1;
	for (n = 1, #h,
		for (k = 1, n,
			v = other(k);
			see(v);
			m++;
			if (k==1,
				h[n] = v;
			);
			if (v && v<=#a,
				a[v] = m;
				while (a[u],
					print (u " " a[u]);
					if (u++ > #a,
						break (3);
					);
				);
			);
		);
	);
}

quit