import java.util.Scanner;
import java.util.Queue;
import java.util.LinkedList;
import java.io.File;
import java.lang.StringBuilder;

public class Tree {	
	
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt(), p=0;
		while ((1<<p)<n) p++;
		int[] deg=new int[n];
		int[][] query=new int[p][n], ans=new int[p][n];
		// determine degrees and leaves
		Queue<Integer> leaves = new LinkedList<Integer>();
		System.out.println("QUERY " + "1".repeat(n));
		for (int x=0;x<n;x++) {
			deg[x] = sc.nextInt();
			if (deg[x]==1) leaves.add(x);
		}
		// prepare queries (01010101, 00110011, 00001111, ...)
		for (int x=0;x<n;x++) {
			for (int j=0;j<p;j++) query[j][x] = (x&(1<<j))!=0 ? 1 : 0;
		}
		// perform queries and store answers
		for (int j=0;j<p;j++) {
			StringBuilder s = new StringBuilder("QUERY ");
			for (int x=0;x<n;x++) s.append(query[j][x]);
			System.out.println(s.toString());
			for (int x=0;x<n;x++) ans[j][x] = sc.nextInt();
		}
		// repeatedly cut off leaves
		int[][] edges = new int[n-1][2];
		int e=0;
		while (!leaves.isEmpty()) {
			// process and remove leaves
			int x=leaves.poll();
			if (deg[x]!=1) continue;
			int y=0;  // find neighbour (unique answer pattern)
			for (int j=0;j<p;j++) y+=(1<<j)*ans[j][x];
			edges[e][0]=x; edges[e][1]=y; e++;
			for (int j=0;j<p;j++) ans[j][y]-=query[j][x];  // update neighbour
			deg[x]--; deg[y]--;
			if (deg[y]==1) leaves.add(y);
		}
		StringBuilder s = new StringBuilder("ANSWER\n");
		for (int i=0;i<e;i++) {
			int x=edges[i][0], y=edges[i][1];
			s.append(x+1); s.append(' '); s.append(y+1); s.append('\n');
		}
		System.out.println(s.toString());
	}
}
