from collections import defaultdict

def solve(_known, _pairs):
    known = set(_known)
    pairs = [ (min(x1,x2),max(x1,x2)) for x1,x2 in _pairs ]
    A = len(pairs)
    alive = [ True for a in range(A) ]

    # two identical pairs
    doubly_alive = []
    for a in range(A):
        for b in range(a):
            if pairs[a] == pairs[b]:
                doubly_alive.append( pairs[a] )
                x1, x2 = pairs[a]
                known.add(x1)
                known.add(x2)
                alive[a] = False
                alive[b] = False

    may_lo, may_hi = max(known)-39, min(known)+39
    must_lo, must_hi = min(known), max(known)

    while True:
        change = False
        # pairs where one end is known
        for a in range(A):
            if not alive[a]: continue
            x1, x2 = pairs[a]
            if x1 in known:
                known.add(x2)
                alive[a] = False
                change = True
            elif x2 in known:
                known.add(x1)
                alive[a] = False
                change = True
        # do stats where our ends are
        seen = defaultdict(int)
        for a in range(A):
            if not alive[a]: continue
            x1, x2 = pairs[a]
            seen[x1] += 1
            seen[x2] += 1
        # update ranges
        must_lo, must_hi = min(known), max(known)
        for x in range(may_lo, must_lo):
            if seen[x] == 0:
                may_lo = x+1
        for x in range(may_hi, must_hi, -1):
            if seen[x] == 0:
                may_hi = x-1
        must_lo = min( must_lo, may_hi-39 )
        must_hi = max( must_hi, may_lo+39 )
        # pairs where one end must fill a gap
        for a in range(A):
            if not alive[a]: continue
            for x in pairs[a]:
                if x not in known and seen[x] == 1 and must_lo <= x <= must_hi:
                    known.add(x)
                    alive[a] = False
                    change = True
        # pairs where one end is impossible
        for a in range(A):
            if not alive[a]: continue
            x1, x2 = pairs[a]
            if x1 < may_lo or x1 > may_hi:
                known.add(x2)
                alive[a] = False
                change = True
            if x2 < may_lo or x2 > may_hi:
                known.add(x1)
                alive[a] = False
                change = True

        if not change: break
            
    for x1, x2 in doubly_alive:
        known.remove(x1)
        known.remove(x2)

    pairs = [ pairs[a] for a in range(A) if alive[a] ] + doubly_alive + doubly_alive
    return known, pairs

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 ))

    known, pairs = solve(known, pairs)
    known = list(sorted(known))
    A = len(pairs)

    assert len(known) + len(pairs) == 40
    if len(known) == 40: continue
    
    counts = [ defaultdict(int), defaultdict(int) ]
    for x1, x2 in pairs:
        s = sums.index( x1+x2 )
        counts[s][x1] += 1
        counts[s][x2] += 1

    tricky = False
    for x in counts[0]:
        if x in counts[1]:
            tricky = True

    if not tricky: continue

    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

