a(n) = { my (v=0, t=Vecrev(digits(n, 3))); for (k=1, #t, if (t[k]==1, v=+3^(k-1)-v, t[k]==2, v=-3^(k-1)-v)); v }

plus = vector(rem=3^logint(10 000, 3))
minus = vector(rem)

{
	for (n=1, oo,
		w=abs(v=a(n));
		if (w<=#plus,
			if (v>0, plus[w]=n,
					 minus[w]=n);
			if (plus[w] && minus[w],
				if (rem--==0,
					break;
				);
			);
		);
	);
	print ("0 0");
	for (n=1, #plus,
		print (n " " minus[n]-plus[n]);
	);
}

quit