Buggy python submission (verdict: Time Limit Exceeded):
N = int(raw_input())

upper = list()
lower = list()

right_end = 0
search_end = 0 
while True:
    if right_end == 0:
        for q in [['.', '.'], ['.', '#'], ['#', '.'], ['#', '#']]:
            print "".join(upper + [q[0]])
            print "".join(lower + [q[1]])

            r = raw_input()
            if r == 'T':
                upper.append(q[0])
                lower.append(q[1])
                break
            elif r == 'end':
                search_end = 1
                break
            if r == 'F' and q == ['#', '#']:
                right_end = 1
    else:
        for q in [['.', '.'], ['.', '#'], ['#', '.'], ['#', '#']]:
            print "".join([q[0]] + upper)
            print "".join([q[1]] + lower)
            
            r = raw_input()
            if r == 'T':
                upper.insert(0,q[0])
                lower.insert(0,q[1])
                break
            elif r == 'end':
                search_end = 1
                break
    if search_end == 1:
        break




Fixed submission:
import sys
N = int(raw_input())
upper = list()
lower = list()

right_end = 0
search_end = 0 
while True:
    if right_end == 0:
        for q in [['.', '.'], ['.', '#'], ['#', '.'], ['#', '#']]:
            print "".join(upper + [q[0]])
            print "".join(lower + [q[1]])
            sys.stdout.flush()

            r = raw_input()
            if r == 'T':
                upper.append(q[0])
                lower.append(q[1])
                break
            elif r == 'end':
                search_end = 1
                break
            if r == 'F' and q == ['#', '#']:
                right_end = 1
    else:
        for q in [['.', '.'], ['.', '#'], ['#', '.'], ['#', '#']]:
            print "".join([q[0]] + upper)
            print "".join([q[1]] + lower)
            sys.stdout.flush()
            
            r = raw_input()
            if r == 'T':
                upper.insert(0,q[0])
                lower.insert(0,q[1])
                break
            elif r == 'end':
                search_end = 1
                break
    if search_end == 1:
        break

Buggy python submission (verdict: Time Limit Exceeded):
N = int(raw_input())

upper = list()
lower = list()

right_end = 0
search_end = 0 
while True:
    if right_end == 0:
        for q in [['.', '.'], ['.', '#'], ['#', '.'], ['#', '#']]:
            print "".join(upper + [q[0]])
            print "".join(lower + [q[1]])

            r = raw_input()
            if r == 'T':
                upper.append(q[0])
                lower.append(q[1])
                if len(upper) == N:
                    search_end = 1
                break
            if r == 'F' and q == ['#', '#']:
                right_end = 1
    else:
        for q in [['.', '.'], ['.', '#'], ['#', '.'], ['#', '#']]:
            print "".join([q[0]] + upper)
            print "".join([q[1]] + lower)
            
            r = raw_input()
            if r == 'T':
                upper.insert(0,q[0])
                lower.insert(0,q[1])
                if len(upper) == N:
                    search_end = 1
                break
    if search_end == 1:
        break




Fixed submission:
import sys
N = int(raw_input())
upper = list()
lower = list()

right_end = 0
search_end = 0 
while True:
    if right_end == 0:
        for q in [['.', '.'], ['.', '#'], ['#', '.'], ['#', '#']]:
            print "".join(upper + [q[0]])
            print "".join(lower + [q[1]])
            sys.stdout.flush()

            r = raw_input()
            if r == 'T':
                upper.append(q[0])
                lower.append(q[1])
                break
            elif r == 'end':
                search_end = 1
                break
            if r == 'F' and q == ['#', '#']:
                right_end = 1
    else:
        for q in [['.', '.'], ['.', '#'], ['#', '.'], ['#', '#']]:
            print "".join([q[0]] + upper)
            print "".join([q[1]] + lower)
            sys.stdout.flush()
            
            r = raw_input()
            if r == 'T':
                upper.insert(0,q[0])
                lower.insert(0,q[1])
                break
            elif r == 'end':
                search_end = 1
                break
    if search_end == 1:
        break