n = int(input())
p = 0
while (2**p)<n: p+=1

# determine degrees and leaves
leaves = []
print("QUERY", "1"*n, flush=True)
deg = list(map(int,input().split()))
for x in range(n):
    if deg[x]==1: leaves.append(x)

# prepare queries (01010101, 00110011, 00001111, ...)
query = ["".join("1" if (x&(1<<j)) else "0" for x in range(n)) for j in range(p)]

# perform queries and store answers
ans = []
for j in range(p):
    print("QUERY", query[j], flush=True)
    ans.append(list(map(int,input().split())))

# repeatedly cut off leaves
edges = []
while leaves:
    # process and remove leaves
    x = leaves.pop(-1)
    if deg[x]!=1: continue;
    y = sum((2**j)*ans[j][x] for j in range(p))  # find neighbour (unique answer pattern)
    edges.append((x,y))
    for j in range(p): ans[j][y]-=int(query[j][x]);  # update neighbour
    deg[x]-=1; deg[y]-=1;
    if deg[y]==1: leaves.append(y);

print("ANSWER")
for x,y in edges:
    print(x+1,y+1)
print(flush=True)
