import java.util.*;

public class d {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);

		long a, b, c, s;

		a = stdin.nextLong();

		while (a != 0) {
			b = stdin.nextLong();
			c = stdin.nextLong();
			s = stdin.nextLong();

			solve(a,b,c,s);
			a = stdin.nextLong();

		}
	}

	public static void solve(long a, long b, long c, long s) {

		boolean[] occurred = new boolean[(int)c];
		occurred[(int)s] = true;
		while (true) {

			int next = (int)((a*s + b)%c);

			if (occurred[next]) break;

			occurred[next] = true;
			s = next;

		}

		for (int i=15; i>=0; i--) {

			boolean zero = false;
			boolean one = false;

			for (int j=0; j<occurred.length; j++) {
				if (occurred[j]) {
					int bit = (j >> i) & 1;
					if (bit == 1)
						one = true;
					else
						zero = true;

					if (one && zero) break;

				}

			}

			if (zero && one)
				System.out.print("?");
			else if (zero)
				System.out.print("0");
			else
				System.out.print("1");


		}
		System.out.println();
	}
}