from collections import defaultdict

fileno = 0
while True:
    N = int( input() )
    if N == 0: break
    assert 15 <= N <= 17

    known = [ int(_) for _ in input().split() ]
    A = int( input() )
    pairs = [ [ int(_) for _ in input().split() ] for a in range(A) ]
    sums = list(set( x1+x2 for x1,x2 in pairs ))

    f = open(f'{fileno:03d}.asy', 'w')

    print('unitsize(1cm);', file=f)

    seen = defaultdict(int)
    for x in known:
        print(f'draw( circle( ({x},0), 0.3 ) );', file=f)
        seen[x] += 1

    for col in range(2):
        for a in range(A):
            x1, x2 = pairs[a]
            if x1 > x2: x1, x2 = x2, x1
            if x1+x2 != sums[col]: continue
            color = ['red','blue'][col]

            print(f'draw( ({x1},0) .. ({(x1+x2)/2.},{(x1-x2)/10.}) .. ({x2},0), {color} );', file=f)
            r1 = 0.3 - 0.08 * seen[x1]
            r2 = 0.3 - 0.08 * seen[x2]
            print(f'filldraw( circle(({x1},0), {r1}), white, {color} );', file=f)
            print(f'filldraw( circle(({x2},0), {r2}), white, {color} );', file=f)
            seen[x1] += 1
            seen[x2] += 1

    print(f'draw( ({min(known)-.3},0.4) -- ({max(known)+.3},0.4), black+4bp );', file=f)

    f.close()
    fileno += 1

