Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years.

There are two sequences of $n$ strings $s_1, s_2, s_3, \ldots, s_{n}$ and $m$ strings $t_1, t_2, t_3, \ldots, t_{m}$. These strings contain only lowercase letters. There might be duplicates among these strings.

Let's call a concatenation of strings $x$ and $y$ as the string that is obtained by writing down strings $x$ and $y$ one right after another without changing the order. For example, the concatenation of the strings "code" and "forces" is the string "codeforces".

The year 1 has a name which is the concatenation of the two strings $s_1$ and $t_1$. When the year increases by one, we concatenate the next two strings in order from each of the respective sequences. If the string that is currently being used is at the end of its sequence, we go back to the first string in that sequence.

For example, if $n = 3, m = 4, s = ${"a", "b", "c"}, $t =$ {"d", "e", "f", "g"}, the following table denotes the resulting year names. Note that the names of the years may repeat. [Image] 

You are given two sequences of strings of size $n$ and $m$ and also $q$ queries. For each query, you will be given the current year. Could you find the name corresponding to the given year, according to the Gapja system?


-----Input-----

The first line contains two integers $n, m$ ($1 \le n, m \le 20$).

The next line contains $n$ strings $s_1, s_2, \ldots, s_{n}$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $1$ and at most $10$.

The next line contains $m$ strings $t_1, t_2, \ldots, t_{m}$. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least $1$ and at most $10$.

Among the given $n + m$ strings may be duplicates (that is, they are not necessarily all different).

The next line contains a single integer $q$ ($1 \le q \le 2\,020$).

In the next $q$ lines, an integer $y$ ($1 \le y \le 10^9$) is given, denoting the year we want to know the name for.


-----Output-----

Print $q$ lines. For each line, print the name of the year as per the rule described above.


-----Example-----
Input
10 12
sin im gye gap eul byeong jeong mu gi gyeong
yu sul hae ja chuk in myo jin sa o mi sin
14
1
2
3
4
10
11
12
13
73
2016
2017
2018
2019
2020

Output
sinyu
imsul
gyehae
gapja
gyeongo
sinmi
imsin
gyeyu
gyeyu
byeongsin
jeongyu
musul
gihae
gyeongja



-----Note-----

The first example denotes the actual names used in the Gapja system. These strings usually are either a number or the name of some animal.

Difficulty: EASY

Solutions:
numberl = []
(a, b) = map(int, input().split())
starr1 = list(map(str, input().split()))
starr2 = list(map(str, input().split()))
num = int(input())
for i in range(num):
	ele = int(input())
	numberl.append(ele)
for i in range(num):
	x = numberl[i] % a
	y = numberl[i] % b
	if x == 0:
		x = a
	if y == 0:
		y = b
	print(starr1[x - 1] + starr2[y - 1])


(n, m) = [int(i) for i in input().split()]
l = [str(i) for i in input().split()]
s = [str(i) for i in input().split()]
a = int(input())
for i in range(a):
	b = int(input())
	print(l[b % n - 1] + s[b % m - 1])


from sys import stdin, stdout
(n, m) = map(int, stdin.readline().split())
s = stdin.readline().split()
t = stdin.readline().split()
q = int(stdin.readline().strip())
years = [int(stdin.readline().strip()) for _ in range(q)]
for y in years:
	stdout.write('{}{}\n'.format(s[(y - 1) % n], t[(y - 1) % m]))


import sys
input = sys.stdin.readline

def getInt():
	return int(input())

def getVars():
	return map(int, input().split())

def getList():
	return list(map(int, input().split()))

def getStr():
	return input().strip()
(n, m) = getVars()
a = input().split()
b = input().split()
q = getInt()
for i in range(q):
	x = getInt()
	print(a[x % n - 1], b[x % m - 1], sep='')


(a, b) = map(int, input().split())
l1 = input().split()
l2 = input().split()
c = int(input())
for x in range(c):
	m = int(input())
	print(l1[(m - 1) % a] + l2[(m - 1) % b])


(n, m) = map(int, input().split())
s = input().split()
t = input().split()
test_case = int(input())
for _ in range(test_case):
	y = int(input())
	print(s[y % n - 1] + t[y % m - 1])


l = list(map(int, input().split()))
l1 = list(input().split())
l2 = list(input().split())
q = int(input())
li = []
while q > 0:
	n = int(input())
	li.append(n)
	q = q - 1
for i in li:
	a = i % l[0]
	b = i % l[1]
	s = l1[a - 1] + l2[b - 1]
	print(s)


def f():
	q = int(input())
	x = (q - 1) % n
	y = (q - 1) % m
	return s[x] + t[y]
(n, m) = [int(s) for s in input().split()]
s = list(input().split())
t = list(input().split())
a = int(input())
for i in range(a):
	print(f())


(n, m) = map(int, input().split())
a = list(input().split())
b = list(input().split())
t = int(input())
for _ in range(t):
	x = int(input())
	f = x % n
	s = x % m
	if f == 0:
		f = n
	if s == 0:
		s = m
	print(a[f - 1] + b[s - 1])


(tamanhoPrimeiraLista, tamanhoSegundaLista) = list(map(int, input().split(' ')))
lista1 = input().split(' ')
lista2 = input().split(' ')
qtdPalavras = int(input())
for _ in range(qtdPalavras):
	ano = int(input())
	print(lista1[(ano - 1) % tamanhoPrimeiraLista] + '' + lista2[(ano - 1) % tamanhoSegundaLista])


(n, m) = list(map(int, input().split()))
ln = input().split()
lm = input().split()
for _ in range(int(input())):
	x = int(input()) - 1
	print(ln[x % n] + lm[x % m])


(n, m) = map(int, input().split())
s = input().split()
t = input().split()
q = int(input())
for i in range(q):
	k = int(input())
	print(s[k % n - 1] + t[k % m - 1])


i = input
i()
a = i().split()
b = i().split()
q = int(i())
while q > 0:
	c = int(i()) - 1
	print(a[c % len(a)] + b[c % len(b)])
	q -= 1


import sys

def solution(a, b, req):
	(n, m) = (len(a), len(b))
	for y in req:
		sys.stdout.write('%s\n' % (a[(y - 1) % n] + b[(y - 1) % m]))

def main():
	while True:
		try:
			(n, m) = [int(i) for i in input().strip().split()]
			a = [i for i in input().strip().split()]
			b = [i for i in input().strip().split()]
			q = int(input().strip())
			req = [int(input().strip()) for i in range(q)]
			solution(a, b, req)
		except EOFError:
			break
main()


boosted = input('')
n = input('').split()
m = input('').split()
queries = int(input(''))
ans = []
for i in range(queries):
	q = int(input(''))
	ans.append(n[q % len(n) - 1] + m[q % len(m) - 1])
for j in ans:
	print(j)


import sys
(n, m) = map(int, sys.stdin.readline().split())
n_strings = sys.stdin.readline().rstrip().split()
m_strings = sys.stdin.readline().rstrip().split()
q = int(sys.stdin.readline())
for year in map(int, sys.stdin):
	year -= 1
	n_index = year % n
	m_index = year % m
	name = n_strings[n_index] + m_strings[m_index]
	print(name)


input()
s = list(input().split())
t = list(input().split())
for num in [int(input()) for _ in ' ' * int(input())]:
	print(s[num % len(s) - 1] + t[num % len(t) - 1])


(N, M) = map(int, input().split())
s1 = list(input().split())
t1 = list(input().split())
q = int(input())
for i in range(q):
	y = int(input())
	p = s1[(y - 1) % len(s1)] + t1[(y - 1) % len(t1)]
	print(p)


def main():
	(m, n) = input().split()
	(m, n) = (int(m), int(n))
	firstArray = [x for x in input().split()]
	secondArray = [x for x in input().split()]
	T = int(input())
	outputs = []
	for i in range(T):
		year = int(input())
		year -= 1
		if year < m and year < n:
			outputs.append(firstArray[year] + secondArray[year])
		elif year > m and year < n:
			a = year % m
			outputs.append(firstArray[a] + secondArray[year])
		elif year < m and year > n:
			a = year % n
			outputs.append(firstArray[year] + secondArray[a])
		else:
			a = year % m
			b = year % n
			outputs.append(firstArray[a] + secondArray[b])
	for i in outputs:
		print(i)
main()


(a, b) = map(int, input().split())
s1 = list(input().split())
s2 = list(input().split())
cases = int(input())
while cases:
	cases -= 1
	num = int(input())
	result = s1[num % a - 1] + s2[num % b - 1]
	print(result)


(n, m) = map(int, input().split())
s = list(input().split())
t = list(input().split())
q = int(input())
for _ in range(q):
	y = int(input())
	print(s[y % len(s) - 1] + t[y % len(t) - 1])


input()
s = list(input().split())
t = list(input().split())
q = int(input())
for i in range(q):
	ind = int(input()) - 1
	print(s[ind % len(s)] + t[ind % len(t)])


(n, m) = (int(x) for x in input().split())
s = input().split()
t = input().split()
q = int(input())
nen = [int(input()) for x in range(q)]
for i in nen:
	x = i - 1
	y = i - 1
	if x >= n:
		x = x % n
	if y >= m:
		y = y % m
	print(s[x] + t[y])


(n, m) = [int(i) for i in input().split()]
n_seq = input().split()
m_seq = input().split()
q = int(input())
for i in range(q):
	y = int(input())
	gap_y = n_seq[y % n - 1] + m_seq[y % m - 1]
	print(gap_y)


numberl = []
(n, m) = map(int, input().split())
s1 = list(map(str, input().split()))
s2 = list(map(str, input().split()))
num = int(input())
for i in range(num):
	ele = int(input())
	numberl.append(ele)
for i in range(num):
	x = numberl[i] % n
	y = numberl[i] % m
	if x == 0:
		x = n
	if y == 0:
		y = m
	print(s1[x - 1] + s2[y - 1])


(n, m) = map(int, input().split())
l = list(map(str, input().split()))
w = list(map(str, input().split()))
q = int(input())
for i in range(q):
	x = int(input())
	y = x % n
	z = x % m
	p = l[y - 1] + w[z - 1]
	print(p)


def korean_year(s, t, year):
	return s[(year - 1) % len(s)] + t[(year - 1) % len(t)]
(n, m) = map(int, input().split())
s = list(input().split())
t = list(input().split())
for _ in range(int(input())):
	print(korean_year(s, t, int(input())))


(n, m) = map(int, input().split())
a = list(input().split())
b = list(input().split())
for _ in range(int(input())):
	i = int(input()) - 1
	print(a[i % n] + b[i % m])


(n, m) = map(int, input().split())
ndata = list(map(str, input().split()))
mdata = list(map(str, input().split()))
q = int(input())
if n == m:
	while q:
		q -= 1
		year = int(input())
		loop = (year - 1) % n
		print(ndata[loop] + mdata[loop])
else:
	while q:
		q -= 1
		year = int(input())
		print(ndata[(year - 1) % n] + mdata[(year - 1) % m])


import math
import sys

def listnuminput():
	return list(map(int, input().split(' ')))

def liststrinput():
	return list(input().split(' '))

def main():
	answer = ''
	(n, m) = listnuminput()
	s = liststrinput()
	t = liststrinput()
	for test in range(int(input())):
		q = int(input())
		answer += s[(q - 1) % n] + t[(q - 1) % m] + '\n'
		pass
	print(answer)
main()


(n, m) = map(int, input().split())
s = input().split()[:n]
t = input().split()[:m]
numbers = int(input())
first = 0
second = 0
list_of_numbers = [int(input()) for i in range(numbers)]
list_of_answers = []
for i in range(n * m):
	list_of_answers.append(s[first] + t[second])
	if first < n - 1:
		first += 1
	else:
		first = 0
	if second < m - 1:
		second += 1
	else:
		second = 0
for i in range(numbers):
	print(list_of_answers[list_of_numbers[i] % (n * m) - 1])


(n, m) = list(map(int, input().split()))
a = list(map(str, input().split(' ')))
b = list(map(str, input().split(' ')))
t = int(input())
for _ in range(t):
	i = int(input())
	i -= 1
	print(a[i % len(a)] + b[i % len(b)])


(n, m) = map(int, input().split())
s = input().split()
t = input().split()
for f in range(int(input())):
	a = int(input())
	print(s[a % n - 1] + t[a % m - 1])


(n, m) = map(int, input().split())
S = input().split()
T = input().split()
q = int(input())
for _ in range(q):
	y = int(input())
	print(S[(y - 1) % n] + T[(y - 1) % m])


(n, m) = map(int, input().split())
list1 = list(map(str, input().split()))
list2 = list(map(str, input().split()))
q = int(input())
for i in range(q):
	y = int(input())
	rem1 = y % n
	rem2 = y % m
	if rem1 == 0 and rem2 != 0:
		pos1 = n - 1
		pos2 = rem2 - 1
	elif rem2 == 0 and rem1 != 0:
		pos2 = m - 1
		pos1 = rem1 - 1
	elif rem1 == 0 and rem2 == 0:
		pos1 = n - 1
		pos2 = m - 1
	else:
		pos1 = rem1 - 1
		pos2 = rem2 - 1
	print(list1[pos1] + list2[pos2])


(x, y) = input().split()
j = int(x)
h = int(y)
a = input().split()
b = input().split()
c = [input() for i in range(int(input()))]
t = ''
for i in c:
	n = int(i) % j
	m = int(i) % h
	t = a[n - 1] + b[m - 1]
	print(t)


(n, m) = list(map(int, input().split(' ')))
s = list(map(str, input().split(' ')))
t = list(map(str, input().split(' ')))
q = int(input())
for i in range(q):
	w = int(input())
	d = w % n
	e = w % m
	st = s[d - 1] + t[e - 1]
	print(st)


(n, m) = map(int, input().split(' '))
s = list(map(str, input().split(' ')))
t = list(map(str, input().split(' ')))
tc = int(input())
for i in range(0, tc):
	k = int(input())
	print(s[(k - 1) % n] + t[(k - 1) % m], end='\n')


(n, m) = [int(x) for x in input().split(' ')]
n_str = input().split(' ')
m_str = input().split(' ')
q = int(input())
years = [int(input()) - 1 for x in range(q)]
for year in years:
	print(n_str[year % n] + m_str[year % m])


(m, n) = input().split(' ')
s = input().split(' ')
t = input().split(' ')
q = int(input())
year = []
table = []
for i in range(q):
	year.append(int(input()))
for j in range(0, len(year)):
	print(s[year[j] % int(m) - 1] + t[year[j] % int(n) - 1])


nm = list(map(int, input().split(' ')))
s = input().split(' ')
t = input().split(' ')
n = int(input())
for i in range(n):
	no = int(input())
	if no % nm[0] == 0:
		x = nm[0] - 1
	else:
		x = no % nm[0] - 1
	if no % nm[1] == 0:
		y = nm[1] - 1
	else:
		y = no % nm[1] - 1
	print(s[x] + t[y])


(n, m) = map(int, input().split())
a = [i for i in input().split()]
b = [i for i in input().split()]
q = int(input())
while q:
	y = int(input())
	j = y - y // n * n
	k = y - y // m * m
	print(a[j - 1] + b[k - 1])
	q -= 1


z = input()
z = z.split(' ')
n = int(z[0])
m = int(z[1])
a = input()
a = a.split(' ')
b = input()
b = b.split(' ')
q = int(input())
for i in range(q):
	n = int(input())
	p = n % len(a)
	q = n % len(b)
	p -= 1
	q -= 1
	str = a[p] + b[q]
	print(str)


(n, m) = map(int, input().split())
a = input().split()
b = input().split()
for i in range(int(input())):
	y = int(input())
	print(a[y % n - 1] + b[y % m - 1])


(n, m) = map(int, input().split())
s = input().split(' ')
t = input().split(' ')
q = int(input())
for _ in range(q):
	x = int(input())
	if x % n:
		result = s[x % n - 1]
	else:
		result = s[n - 1]
	if x % m:
		result2 = t[x % m - 1]
	else:
		result2 = t[m - 1]
	print(result + result2)


(n, m) = input().split()
n = int(n)
m = int(m)
li = input().split()
li1 = input().split()
q = int(input())
while q:
	k = int(input())
	i = k % n
	j = k % m
	print(li[i - 1] + li1[j - 1])
	q -= 1


a = input()
n = int(a.split(' ')[0])
m = int(a.split(' ')[1])
s = input()
t = input()
ttl = int(input())
for i in range(0, ttl):
	year = int(input())
	idx1 = year % n if year % n > 0 else n
	idx2 = year % m if year % m > 0 else m
	name = s.split(' ')[idx1 - 1] + t.split(' ')[idx2 - 1]
	print(name)


a = [int(j) for j in input().split()]
n = a[0]
m = a[1]
c = input().split()
d = input().split()
c = [c[-1]] + c
d = [d[-1]] + d
b = int(input())
for ii in range(b):
	e = int(input())
	print(c[e % n] + d[e % m])


import sys
import math
input = sys.stdin.readline
(n, m) = map(int, input().split())
narr = input().split()
marr = input().split()
q = int(input())
for _ in range(q):
	t = int(input())
	curr1 = t % n
	curr2 = t % m
	ans = ''
	if curr1 == 0:
		ans = ans + narr[-1]
	else:
		ans = ans + narr[curr1 - 1]
	if curr2 == 0:
		ans = ans + marr[-1]
	else:
		ans = ans + marr[curr2 - 1]
	print(ans)


(n, m) = (int(i) for i in input().split())
(s, t, q) = (input().split(), input().split(), int(input()))
for _ in range(q):
	y = int(input())
	res = s[(y - 1) % n] + t[(y - 1) % m]
	print(res)


numberl = []
(n, m) = map(int, input().split())
starr1 = list(map(str, input().split()))
starr2 = list(map(str, input().split()))
nu = int(input())
for i in range(nu):
	ele = int(input())
	numberl.append(ele)
for i in range(nu):
	x = numberl[i] % n
	y = numberl[i] % m
	if x == 0:
		x = n
	if y == 0:
		y = m
	print(starr1[x - 1] + starr2[y - 1])


s = input('').split(' ')
n = int(s[0])
m = int(s[1])
s = input('').split(' ')
t = input('').split(' ')
q = int(input(''))
for _ in range(q):
	a = int(input(''))
	ans = s[(a - 1) % n] + t[(a - 1) % m]
	print(ans)


(a, d) = list(map(int, input().split()))
b = input().split()
c = input().split()
q = int(input())
for i in range(q):
	j = int(input()) - 1
	print(b[j % a] + c[j % d])


(n, m) = map(int, input().rstrip().split())
S = []
S = list(input().rstrip().split())
T = list(input().rstrip().split())
q = int(input())
y = []
for i in range(q):
	y.append(int(input()))
for i in y:
	si = (i - 1) % n
	ti = (i - 1) % m
	print(S[si] + T[ti])


(n, m) = list(map(int, input().split()))
s = input().split()
t = input().split()
am = int(input())
for _ in range(am):
	num = int(input()) - 1
	ans = s[num % n] + t[num % m]
	print(ans)


(a, b) = map(int, input().split())
n = input().split()
m = input().split()
q = int(input())
for i in range(q):
	y = int(input())
	if y > a:
		s1 = int(y % a - 1)
	else:
		s1 = int(y - 1)
	if y > b:
		s2 = int(y % b - 1)
	else:
		s2 = int(y - 1)
	print(n[s1] + m[s2])


(n, m) = map(int, input().split())
A = list(map(str, input().split()))
B = list(map(str, input().split()))
q = int(input())
while q > 0:
	x = int(input())
	A_idx = (x - 1) % n
	B_idx = (x - 1) % m
	print(A[A_idx] + B[B_idx])
	q -= 1


(n, m) = [int(x) for x in input().split()]
s = []
t = []
y = []
s_raw = input()
t_raw = input()
s = s_raw.split()
t = t_raw.split()
q = int(input())
for i in range(0, q):
	y.append(int(input()))
for i in range(0, q):
	j = (y[i] - 1) % n
	k = (y[i] - 1) % m
	print(s[j], end='')
	print(t[k])


nm = input().split()
n = int(nm[0])
m = int(nm[1])
s = input().split()
t = input().split()
q = int(input())
i = 0
while i < q:
	y = int(input())
	yn = y % n
	ym = y % m
	print(s[yn - 1] + t[ym - 1])
	i += 1


(N, M) = map(int, input().split())
L1 = list(map(str, input().split()))
L2 = list(map(str, input().split()))
L1.insert(0, 1)
L2.insert(0, 1)
Q = int(input())
while Q:
	X = int(input())
	X = X % (N * M)
	if X == 0:
		X = N * M
	Y1 = X % N
	Y2 = X % M
	if Y1 == 0:
		Y1 = N
	if Y2 == 0:
		Y2 = M
	ANS = L1[Y1] + L2[Y2]
	print(ANS)
	Q -= 1


(n, m) = [int(_) for _ in input().split()]
s = input().split()
t = input().split()
q = int(input())
l = []
for _ in range(q):
	y = int(input())
	l.append(s[(y - 1) % n] + t[(y - 1) % m])
for output in l:
	print(output)


(n, m) = [int(zax) for zax in input().split()]
p = input().split()
q = input().split()
t = int(input())
for case in range(t):
	year = int(input())
	ind1 = year % n - 1
	ind2 = year % m - 1
	print(p[ind1] + q[ind2])


def new_year_and_naming():
	(n, m) = input().split(' ')
	(n, m) = (int(n), int(m))
	strings_n = input().split(' ')
	strings_m = input().split(' ')
	num_answer = int(input())
	count = 0
	target_year = []
	while count < num_answer:
		target_year += [int(input())]
		count += 1
	all_names = []
	maxy = max(n, m)
	for i in range(0, n * m):
		n_idx = i % n
		m_idx = i % m
		all_names += [strings_n[n_idx] + strings_m[m_idx]]
	for (idx, target) in enumerate(target_year):
		print(all_names[(target - 1) % (n * m)])
new_year_and_naming()


(n, m) = map(int, input().split())
x = []
s = input().split()
t = input().split()
q = int(input())
for j in range(q):
	y = int(input())
	x.append(s[y % n - 1] + t[y % m - 1])
for i in range(q):
	print(x[i])


a = list(input().split())
s = list(input().split())
t = list(input().split())
q = int(input())
answer = []
for x in range(q):
	p = int(input())
	i = p % int(a[0]) - 1
	j = p % int(a[1]) - 1
	result = s[i] + t[j]
	answer.append(result)
for y in answer:
	print(y)


(n, m) = map(int, input().split())
s = input().split()
t = input().split()
q = int(input())
for qu in range(q):
	x = int(input()) - 1
	ans = s[x % n] + t[x % m]
	print(ans)


(n, m) = map(int, input().split())
s = input().split()
t = input().split()
q = int(input())
for i in range(0, q):
	y = int(input())
	sd = s[y % n - 1]
	td = t[y % m - 1]
	print(sd + td)


inp = input()
inp = inp.split(' ')
sen1_len = int(inp[0])
sen2_len = int(inp[1])
starting_string = input()
ending_string = input()
starting_string = starting_string.split(' ')
ending_string = ending_string.split(' ')
number_of_years = int(input())
list_of_years = []
for i in range(number_of_years):
	current_year = int(input())
	list_of_years.append(current_year)
answer = []
for current_year in list_of_years:
	temp_answer = ''
	first_index = current_year % sen1_len - 1
	second_index = current_year % sen2_len - 1
	temp_answer += starting_string[first_index] + ending_string[second_index]
	answer.append(temp_answer)
for current_answer in answer:
	print(current_answer)


(n, m) = map(int, input().split())
s = input().split()
t = input().split()
for i in range(int(input())):
	x = int(input())
	print(s[x % n - 1] + t[x % m - 1])


(a, b) = map(int, input().split())
l = list(map(str, input().split()))
t = list(map(str, input().split()))
x = int(input())
for i in range(x):
	c = int(input())
	j = c % a
	m = c % b
	print(l[j - 1] + t[m - 1])


modulonums = list(map(int, input().split()))
nlist = list(input().split())
mlist = list(input().split())

def stringcount(number):
	a = number % modulonums[0]
	b = number % modulonums[1]
	return nlist[a - 1] + mlist[b - 1]
for i in range(int(input())):
	print(stringcount(int(input())))


from collections import Counter, defaultdict, deque
import heapq as hq
import math
import sys
input = sys.stdin.readline

def solve():
	(n, m) = [int(x) for x in input().split()]
	s = [x for x in input().strip().split()]
	t = [x for x in input().strip().split()]
	q = int(input())
	for i in range(q):
		y = int(input())
		print(s[y % n - 1] + t[y % m - 1])
tt = 1
for test in range(tt):
	solve()


(n, m) = [int(elem) for elem in input().split()]
s = {}
i = 1
for elem in input().split():
	s[i] = elem
	i += 1
i = 1
t = {}
for elem in input().split():
	t[i] = elem
	i += 1
for i in range(int(input())):
	year = int(input())
	index0 = year % n
	index1 = year % m
	if index0 == 0:
		index0 = n
	if index1 == 0:
		index1 = m
	print(s[index0] + t[index1])


l = list(map(int, input().split()))
p = list(map(str, input().split()))
r = list(map(str, input().split()))
q = int(input())
n = l[0]
m = l[1]
a = n * m
while q:
	y = int(input())
	if y > a:
		y = y % a
	i1 = y % n
	i2 = y % m
	if i1 == 0:
		i1 = n
	if i2 == 0:
		i2 = m
	ans = p[i1 - 1] + r[i2 - 1]
	print(ans)
	q -= 1


(n, m) = list(map(int, input().split()))
s = input().split()
t = input().split()
q = int(input())
for _ in range(q):
	a = int(input()) - 1
	print(s[a % n] + t[a % m])


c = list(map(int, input().split()))
a = input().split(' ')
b = input().split(' ')
m = len(a)
n = len(b)
d = int(input())
x = int(0)
while x < d:
	e = int(input())
	f = e % m
	g = e % n
	print(a[f - 1] + b[g - 1])
	x = x + 1


(n, m) = map(int, input().split())
s = list(map(str, input().split()))
t = list(map(str, input().split()))
q = int(input())
year = [int(input()) for _ in range(q)]
for i in range(q):
	j = year[i] % n - 1
	k = year[i] % m - 1
	print(s[j] + t[k])


(n, m) = map(int, input().split())
s = list(map(str, input().split()))
s1 = list(map(str, input().split()))
for i in range(int(input())):
	l = int(input())
	print(s[l % n - 1] + s1[l % m - 1])


(n, m) = map(int, input().split())
s = input().split()
t = input().split()
q = int(input())
for _ in range(q):
	i = int(input())
	result = s[(i - 1) % n] + t[(i - 1) % m]
	print(result)


(n, m) = map(int, input().split())
a = list(input().split())
b = list(input().split())
q = int(input())
for _ in range(q):
	y = int(input())
	print(a[(y - 1) % n] + b[(y - 1) % m])


(a, b) = map(int, input().split())
name1 = list(input().split())
name2 = list(input().split())
years = int(input())
yearslist = []
for i in range(years):
	count = int(input())
	yearslist.append(count)
mainname = []
for i in yearslist:
	lastname = name1[(i - 1) % a] + name2[(i - 1) % b]
	mainname.append(lastname)
for i in mainname:
	print(i)


values = [int(i) for i in input().split()]
strings_n = [str(i) for i in input().split()]
strings_m = [str(i) for i in input().split()]
n = values[0]
m = values[1]
q = int(input())
x = []
for i in range(q):
	y = int(input())
	x.append(y)
for i in range(q):
	x_n = x[i] % n
	x_m = x[i] % m
	a = strings_n[x_n - 1] + strings_m[x_m - 1]
	print(a)


w = input()
a = w.split()
n = int(a[0])
m = int(a[1])
s = str(input())
t = str(input())
s = s.split()
t = t.split()
q = int(input())
lst = list()
for i in range(q):
	y = int(input())
	lst.append(y)
for i in lst:
	print(s[(i - 1) % n] + t[(i - 1) % m])


list_sizes = input().split(' ')
for i in range(len(list_sizes)):
	list_sizes[i] = int(list_sizes[i])
list1 = input().split(' ')
list2 = input().split(' ')
c = int(input())
inputs = []
outputs = []
for i in range(c):
	inputs.append(int(input()))
for i in range(c):
	outputs.append(list1[(inputs[i] - 1) % list_sizes[0]] + list2[(inputs[i] - 1) % list_sizes[1]])
for i in range(c):
	print(outputs[i])


(n, m) = map(int, input().split())
pol = input().split()
kan = input().split()
a = []
for i in range(1, n * m + 1):
	if i % n == 0:
		a.append(pol[n - 1])
	else:
		a.append(pol[i % n - 1])
	if i % m == 0:
		a[-1] += kan[m - 1]
	else:
		a[-1] += kan[i % m - 1]
p = int(input())
for i in range(p):
	t = int(input())
	print(a[t % (n * m) - 1])


number = []
(n, m) = map(int, input().split())
starr1 = list(map(str, input().split()))
starr2 = list(map(str, input().split()))
num = int(input())
for i in range(num):
	ele = int(input())
	number.append(ele)
for i in range(num):
	x = number[i] % n
	y = number[i] % m
	if x == 0:
		x = n
	if y == 0:
		y = m
	print(starr1[x - 1] + starr2[y - 1])


(n, m) = map(int, input().split())
S = input().split()
T = input().split()
q = int(input())
d1 = len(S)
d2 = len(T)
for i in range(q):
	year = int(input())
	y1 = (year - 1) % d1
	y2 = (year - 1) % d2
	s = S[y1]
	t = T[y2]
	print(s + t)


s = list(map(int, input().split()))
(n, m) = (s[0], s[1])
sl = input().split()
tl = input().split()
q = int(input())
for _ in range(q):
	y = int(input())
	sx = (y - 1) % n
	tx = (y - 1) % m
	print(sl[sx] + tl[tx])


(n, m) = map(int, input().split())
a = input().split()
b = input().split()
q = int(input())
for _ in range(q):
	year = int(input())
	ans = ''
	ans += a[year % n - 1]
	ans += b[year % m - 1]
	print(ans)


import math
import sys
import itertools
import fractions
wtf = sys.stdin.read()
wtf = wtf.strip().split('\n')
(n, m) = map(int, wtf[0].split())
S = wtf[1].split()
T = wtf[2].split()
q = int(wtf[3])
for qi in wtf[4:]:
	tmp = int(qi)
	print(S[tmp % n - 1] + T[tmp % m - 1])


_ = input()
first_string = input().split()
second_string = input().split()
first_length = len(first_string)
second_length = len(second_string)
queries = int(input())
for i in range(queries):
	year = int(input()) - 1
	string = ''
	if year < first_length:
		string += first_string[year]
	else:
		string += first_string[year % first_length]
	if year < second_length:
		string += second_string[year]
	else:
		string += second_string[year % second_length]
	print(string)


(n, m) = map(int, input().split())
s = input().split()
t = input().split()
q = int(input())
for k in range(q):
	nombre = int(input())
	a = nombre % n
	b = nombre % m
	if a == 0:
		res1 = s[n - 1]
	else:
		res1 = s[a - 1]
	if b == 0:
		res2 = t[m - 1]
	else:
		res2 = t[b - 1]
	res = res1 + res2
	print(res)


from math import floor

def get_list_input():
	s = input()
	return s.split(' ')

def get_int_input():
	return int(input())

def get_year_string(year, n, m, n_list, m_list):
	n_number = year - floor(year / n) * n - 1
	m_number = year - floor(year / m) * m - 1
	n_string = n_list[n_number]
	m_string = m_list[m_number]
	return '{}{}'.format(n_string, m_string)

def main():
	nm = get_list_input()
	n = int(nm[0])
	m = int(nm[1])
	n_list = get_list_input()
	m_list = get_list_input()
	q = get_int_input()
	year_list = []
	for year in range(q):
		new_year = get_int_input()
		year_list.append(new_year)
	for year in year_list:
		print(get_year_string(year, n, m, n_list, m_list))
main()


(n, m) = map(int, input().split())
l1 = [str(a) for a in input().split()]
l2 = [str(b) for b in input().split()]
q = int(input())
l3 = []
for i in range(q):
	s = ''
	a = int(input())
	if a <= n:
		s = l1[a - 1]
	else:
		c = a % n
		if c == 0:
			c = n
		s = l1[c - 1]
	if a <= m:
		s = s + l2[a - 1]
	else:
		c = a % m
		if c == 0:
			c = m
		s = s + l2[c - 1]
	l3.append(s)
for i in range(q):
	print(l3[i])


(n, m) = map(int, input().split())
s = list(map(str, input().rstrip().split()))
t = list(map(str, input().rstrip().split()))
q = int(input())
for i in range(q):
	y = int(input())
	if y % n > 0:
		if y % m > 0:
			print('{}{}'.format(s[y % n - 1], t[y % m - 1]))
		else:
			print('{}{}'.format(s[y % n - 1], t[m - 1]))
	elif y % m > 0:
		print('{}{}'.format(s[n - 1], t[y % m - 1]))
	else:
		print('{}{}'.format(s[n - 1], t[m - 1]))


(n, m) = map(int, input().split())
a = input().split()
b = input().split()
col = n * m
k = int(input())
for i in range(k):
	q = int(input())
	print(a[(q - 1) % n], b[(q - 1) % m], sep='')


import sys
(outer_size, inner_size) = map(int, input().split())
outer = input().split()
inner = input().split()
for i in range(int(input())):
	year = int(input())
	ostr = outer[year % outer_size - 1]
	istr = inner[year % inner_size - 1]
	print(ostr + istr)


(n, m) = map(int, input().split())
s = list(input().split())
t = list(input().split())
q = int(input())
for i in range(q):
	g = int(input())
	i = g % n
	j = g % m
	print(s[i - 1] + t[j - 1])


(n, m) = map(int, input().strip().split())
s = input().split(' ')
t = input().split(' ')
q = int(input())
for i in range(q):
	year = int(input())
	year -= 1
	first_index = year % n
	second_index = year % m
	print(s[first_index] + t[second_index])


(n, m) = map(int, input().split())
s = input().split()
t = input().split()
q = int(input())
for i in range(q):
	y = int(input())
	print(s[y % len(s) - 1] + t[y % len(t) - 1])


import math

def main():
	(n, m) = map(int, input().split())
	s = input().split()
	t = input().split()
	q = int(input())
	for _ in range(q):
		year = int(input())
		indexS = year % n - 1
		indexT = year % m - 1
		print(s[indexS] + t[indexT])
main()


(n, m) = map(int, input().split())
a = input().split()
b = input().split()
for _ in range(int(input())):
	k = int(input()) - 1
	print(a[k % n] + b[k % m])


(n, m) = map(int, input().split())
s1 = input().split()
s2 = input().split()
Q = int(input())
for q in range(Q):
	x = int(input()) - 1
	print(s1[x % n] + s2[x % m])


(m, n) = map(int, input().split())
lst1 = list(input().split())
lst2 = list(input().split())
t = int(input())
for i in range(t):
	val = int(input())
	temp1 = val % m
	temp2 = val % n
	if temp1 == 0:
		temp1 = m
	if temp2 == 0:
		temp2 = n
	print(lst1[temp1 - 1] + lst2[temp2 - 1])


def solve(s, t, queries):
	for query in queries:
		i = (query - 1) % len(s)
		j = (query - 1) % len(t)
		name = f'{s[i]}{t[j]}'
		print(name)
(n, m) = [int(x) for x in input().split()]
s = [x for x in input().split()]
t = [x for x in input().split()]
q = int(input())
queries = []
for i in range(q):
	queries.append(int(input()))
solve(s, t, queries)


import math as mt
import sys, string, bisect
input = sys.stdin.readline
import random
from collections import deque, defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
(n, m) = M()
l = Ls()
a = Ls()
q = I()
for _ in range(q):
	s = I()
	print(l[(s - 1) % len(l)], end='')
	print(a[(s - 1) % len(a)])


(a, b) = map(int, input().split())
l1 = input().split()
l2 = input().split()
t = int(input())
for i in range(t):
	x = int(input())
	print(l1[(x - 1) % a] + l2[(x - 1) % b])


(n, m) = map(int, input().split())
l1 = [i for i in input().split()]
l2 = [i for i in input().split()]
a = len(l1)
b = len(l2)
for tc in range(int(input())):
	k = int(input())
	ans = l1[k % a - 1] + l2[k % b - 1]
	print(ans)


import sys
import collections
from collections import Counter, deque
import itertools
import math
import timeit
import random

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	divisors = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				divisors.append(i)
			else:
				divisors.extend([i, n // i])
	return divisors

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def flin(d, x, default=-1):
	left = right = -1
	for i in range(len(d)):
		if d[i] == x:
			if left == -1:
				left = i
			right = i
	if left == -1:
		return (default, default)
	else:
		return (left, right)

def ceil(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)
(n, m) = mi()
a = [x for x in input().split()]
b = [x for x in input().split()]
t = ii()
for _ in range(t):
	p = ii()
	p -= 1
	print(f'{a[p % n]}{b[p % m]}')


(N, M) = map(int, input().split())
S = input().split()
T = input().split()
for _ in range(int(input())):
	a = int(input()) - 1
	print(S[a % N] + T[a % M])


(n, m) = map(int, input().split())
s1 = list(input().split())
s2 = list(input().split())
q = int(input())
for i in range(q):
	num = int(input())
	num = num - 1
	s = s1[num % n] + s2[num % m]
	print(s)


import math
import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
first = list(input().split())
second = list(input().split())
q = int(input())
for i in range(q):
	x = int(input())
	ans = first[(x - 1) % n]
	ans += second[(x - 1) % m]
	print(ans)


temp = [int(s) for s in input().split()]
n = [s for s in input().split()]
m = [s for s in input().split()]
a = temp[0]
b = temp[1]
t = int(input())
for i in range(t):
	k = int(input()) - 1
	print(n[k % a] + m[k % b])


import sys
from sys import stdin, stdout
import bisect
import math
import heapq

def modinv(n, p):
	return pow(n, p - 2, p)

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())
import math

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l

def main():
	(n, m) = cin()
	a = []
	b = []
	s = sin()
	ss = sin()
	d = ''
	for i in s:
		if i == ' ':
			a.append(d)
			d = ''
			continue
		d += i
	a.append(d)
	d = ''
	for i in ss:
		if i == ' ':
			b.append(d)
			d = ''
			continue
		d += i
	b.append(d)
	t = inin()
	for _ in range(t):
		p = inin()
		q = p
		q = q % n
		p = p % m
		print(a[q - 1] + b[p - 1])
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'

def readnumbers(zero=0):
	conv = ord if py2 else lambda x: x
	A = []
	numb = zero
	sign = 1
	i = 0
	s = sys.stdin.buffer.read()
	try:
		while True:
			if s[i] >= b'0'[0]:
				numb = 10 * numb + conv(s[i]) - 48
			elif s[i] == b'-'[0]:
				sign = -1
			elif s[i] != b'\r'[0]:
				A.append(sign * numb)
				numb = zero
				sign = 1
			i += 1
	except:
		pass
	if s and s[-1] >= b'0'[0]:
		A.append(sign * numb)
	return A
main()


def find_name():
	(n, m) = map(int, input().split())
	s = list(input().split())
	t = list(input().split())
	q = int(input())
	for __ in range(q):
		y = int(input())
		print(s[y % n - 1] + t[y % m - 1])
find_name()


(a, b) = input().split(' ')
c = input().split(' ')
d = input().split()
m = int(input())
for i in range(m):
	n = int(input())
	print(c[n % int(a) - 1], end='')
	print(d[n % int(b) - 1])


(n, m) = list(map(int, input().split(' ')))
s = input().split(' ')
t = input().split(' ')
testcases = int(input())
for i in range(testcases):
	year = int(input())
	print(s[year % len(s) - 1] + t[year % len(t) - 1])


(n, m) = map(int, input().split())
a = list(map(str, input().split()))
b = list(map(str, input().split()))
q = int(input())
for i in range(q):
	x = int(input())
	i = x % n
	o = x % m
	z = a[i - 1] + b[o - 1]
	print(z)


(n, m) = list(map(int, input().split(' ')))
s = input().split(' ')
t = input().split(' ')
times = int(input())
for i in range(times):
	year = int(input()) - 1
	sIndex = year % len(s)
	tIndex = year % len(t)
	string = f'{s[sIndex]}{t[tIndex]}'
	print(string)


(n, m) = map(int, input().split())
a = list(input().split())
b = list(input().split())
a.insert(0, a[n - 1])
b.insert(0, b[m - 1])
for _ in range(int(input())):
	x = int(input())
	print(a[x % n] + b[x % m])


(n, k) = map(int, input().split())
s = list(input().split())
t = list(input().split())
q = int(input())
p = [int(input()) for i in range(q)]
for x in range(q):
	amari_s = p[x] % len(s)
	amari_t = p[x] % len(t)
	print(s[amari_s - 1] + t[amari_t - 1])


(n, m) = map(int, input().split())
l1 = input().split()
l2 = input().split()
q = int(input())
for _ in range(q):
	y = int(input()) - 1
	print(l1[y % n] + l2[y % m])


(n, m) = list(map(int, input().split(' ')))
ns = input().split(' ')
ms = input().split(' ')
q = int(input())
out = []
for i in range(q):
	y = int(input())
	out.append(ns[(y - 1) % len(ns)] + ms[(y - 1) % len(ms)])
for o in out:
	print(o)


(n, m) = map(int, input().split())
a = list(input().split())
b = list(input().split())
t = int(input())
for i in range(t):
	x = int(input())
	print(a[(x - 1) % n] + b[(x - 1) % m])


(n, m) = map(int, input().split())
a = list(input().split())
b = list(input().split())
t = int(input())
for test in range(t):
	x = int(input())
	d = (x - 1) % (n * m)
	e = d % n
	f = d % m
	res = a[e] + b[f]
	print(res)


(a, b) = map(int, input().split())
ls1 = list(input().split())
ls2 = list(input().split())
q = int(input())
for _ in range(q):
	n = int(input())
	n = n - 1
	print(ls1[n % a] + ls2[n % b])


(n, m) = map(int, input().split())
s = input().split()
t = input().split()
q = int(input())
for _ in range(q):
	y = int(input())
	word = ''
	if y > n:
		n1 = y % n
		word += s[n1 - 1]
	else:
		word += s[y - 1]
	if y > m:
		m1 = y % m
		word += t[m1 - 1]
	else:
		word += t[y - 1]
	print(word)


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
S = [str(i) for i in input().split()]
T = [str(i) for i in input().split()]
q = int(input())
for _ in range(q):
	y = int(input())
	print(S[(y - 1) % n] + T[(y - 1) % m])


(n, m) = map(int, input().split())
str1 = input().split()
str2 = input().split()
q = int(input())
while q:
	q = q - 1
	inp = int(input())
	in1 = inp % len(str1)
	in2 = inp % len(str2)
	print(str1[in1 - 1] + str2[in2 - 1])


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
xn = input().strip().split()
xm = input().strip().split()
q = int(input())
for _ in range(q):
	y = int(input())
	print(xn[(y - 1) % len(xn)] + xm[(y - 1) % len(xm)])


(n, m) = list(map(int, str(input()).split(' ')))
s = str(input()).split(' ')
t = str(input()).split(' ')
q = int(input())
for i in range(0, q):
	y = int(input())
	print(s[y % n - 1] + t[y % m - 1])


import sys
(n, m) = list(map(int, sys.stdin.readline().split()))
a = sys.stdin.readline().split()
b = sys.stdin.readline().split()
q = int(input())
ans = []
for _ in range(q):
	r = int(input())
	ans.append(a[(r - 1) % n] + b[(r - 1) % m])
for i in ans:
	print(i)


nm = input()
list1 = [c for c in input().split()]
list2 = [c for c in input().split()]
out = []
n = len(list1)
m = len(list2)
t = int(input())
for i in range(t):
	s = int(input())
	a = s % n - 1
	b = s % m - 1
	kq = list1[a] + list2[b]
	out.append(kq)
for i in range(t):
	print(out[i])


(n, m) = map(int, input().split())
s = list(map(str, input().split()))
t = list(map(str, input().split()))
for i in range(int(input())):
	temp = int(input())
	a = temp % n
	b = temp % m
	if a == 0:
		a = n - 1
	else:
		a = a - 1
	if b == 0:
		b = m - 1
	else:
		b = b - 1
	print(s[a] + t[b])


import sys
import math
import heapq
import collections

def inputnum():
	return int(input())

def inputnums():
	return map(int, input().split())

def inputlist():
	return list(map(int, input().split()))

def inputstring():
	return [x for x in input()]

def inputstringnum():
	return [ord(x) - ord('a') for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
(n, m) = inputnums()
a = list(input().split())
b = list(input().split())
q = inputnum()
for i in range(q):
	y = inputnum() - 1
	print(a[y % n] + b[y % m])


(n, m) = map(int, input().split())
s1 = list(map(str, input().split()))
s2 = list(map(str, input().split()))
q = int(input())
for i in range(q):
	a = int(input())
	ans = ''
	if a <= n:
		ans = ans + s1[a - 1]
	if a > n:
		val = a % n
		ans = ans + s1[val - 1]
	if a <= m:
		ans = ans + s2[a - 1]
	if a > m:
		val = a % m
		ans = ans + s2[val - 1]
	print(ans)


I = input
I()
s = I().split()
t = I().split()
for _ in [0] * int(I()):
	y = int(I()) - 1
	print(s[y % len(s)] + t[y % len(t)])


(n1, n2) = input().split(' ')
(n1, n2) = (int(n1), int(n2))
s1 = input().split(' ')
s2 = input().split(' ')
n = int(input())
for i in range(n):
	x = int(input())
	index1 = x % n1 - 1
	index2 = x % n2 - 1
	index1 = n1 - 1 if index1 == -1 else index1
	index2 = n2 - 1 if index2 == -1 else index2
	name = s1[index1] + s2[index2]
	print(name)


(n, m) = map(int, input().split(' '))
start = input().split()
end = input().split()
cases = int(input())
for _ in range(cases):
	y = int(input())
	print(start[y % n - 1] + end[y % m - 1])


(n, m) = map(int, input().split())
s = input().split()
t = input().split()
q = int(input())
for _ in range(q):
	x = int(input()) - 1
	print(s[x % len(s)] + t[x % len(t)])


(m, n) = [int(x) for x in input().split(' ')]
li1 = [x for x in input().split(' ')]
li2 = [x for x in input().split(' ')]
q = int(input())
for _ in range(q):
	year = int(input())
	(a, b) = ((year - 1) % m, (year - 1) % n)
	print(li1[a] + li2[b])


(n, m) = map(int, input().split())
a = str(input()).split()
b = str(input()).split()
t = int(input())
for i in range(t):
	k = int(input())
	print(a[k % n - 1] + b[k % m - 1])


import sys
[n, m] = [int(i) for i in sys.stdin.readline().split()]
s = sys.stdin.readline().strip().split()
t = sys.stdin.readline().strip().split()
q = int(sys.stdin.readline())
ans_arr = []
for i in range(q):
	y = int(sys.stdin.readline())
	y -= 1
	ans_arr.append(s[y % n] + t[y % m])
print('\n'.join(ans_arr))


(n, m) = map(int, input().split())
ln = list(input().split())
lm = list(input().split())
t = int(input())
for i in range(t):
	x = int(input())
	print(ln[x % n - 1] + lm[x % m - 1])


(n, m) = map(int, input().split())
l = list(map(str, input().split()))
d = list(map(str, input().split()))
for u in range(int(input())):
	x = int(input())
	r = ''
	r = r + l[x % n - 1] + d[x % m - 1]
	print(r)


import sys, math
MOD = 998244353
(n, m) = map(int, input().split())
a = list(input().split())
b = list(input().split())
for _ in range(int(input())):
	t = int(input())
	print(a[(t - 1) % n] + b[(t - 1) % m])


(n, m) = map(int, input().split())
a = input().split()
b = input().split()
q = int(input())
for _ in range(q):
	qq = int(input()) - 1
	print(a[qq % n] + b[qq % m])


(m, n) = map(int, input().strip().split())
s = [i for i in input().strip().split()]
t = [i for i in input().strip().split()]
q = int(input().strip())
for _ in range(q):
	x = int(input().strip())
	print(s[(x - 1) % m] + t[(x - 1) % n])


from sys import stdin
(n, m) = map(int, stdin.readline().split())
a = [i for i in stdin.readline().split()]
b = [i for i in stdin.readline().split()]
t = int(stdin.readline().strip())
for _ in range(t):
	c = int(stdin.readline().strip())
	print(a[(c - 1) % n] + b[(c - 1) % m])


(N, M) = map(int, input().split())
A = input().split()
B = input().split()
T = int(input())
for t in range(T):
	x = int(input()) - 1
	i = x % N
	j = x % M
	print(A[i] + B[j])


(n, m) = map(int, input().split())
a = list(input().split())
b = list(input().split())
t = int(input())
for i in range(t):
	q = int(input())
	r1 = q % n
	r2 = q % m
	s1 = a[r1 - 1]
	s2 = b[r2 - 1]
	print(s1 + s2)


(n, m) = map(int, input().split())
s = input().split()
t = input().split()
q = int(input())
for _ in range(q):
	x = int(input())
	x -= 1
	p1 = x % n
	p2 = x % m
	print(s[p1], end='')
	print(t[p2])


(n, m) = map(int, input().split())
s = input().split()
t = input().split()
for _ in range(int(input())):
	y = int(input())
	a = y % n
	b = y % m
	print(s[a - 1] + t[b - 1])


(n, m) = [int(ele) for ele in input().split()]
s = [ele for ele in input().split()]
t = [ele for ele in input().split()]
q = int(input())
while q > 0:
	y = int(input())
	i1 = y % n - 1
	i2 = y % m - 1
	print(s[i1] + t[i2])
	q -= 1


(n, m) = map(int, input().split())
s = list(map(str, input().split()))
t = list(map(str, input().split()))
q = int(input())
for i in range(q):
	qi = int(input())
	c = s[(qi - 1) % n] + t[(qi - 1) % m]
	print(c)


(n, m) = map(int, input().strip().split())
s = input().split()
t = input().split()
q = int(input())
for i in range(q):
	y = int(input())
	k = y % n
	l = y % m
	print(s[k - 1], end='')
	print(t[l - 1])


(a, b) = map(int, input().split())
s = input()
l = s.split()
t = input()
r = t.split()
q = int(input())
for i in range(q):
	n = int(input())
	print(l[n % len(l) - 1] + r[n % len(r) - 1])


import os, sys
from io import BytesIO, IOBase
from fractions import Fraction

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(str, input().split())

def li():
	return list(mi())
import math
for i in range(1):
	(n, m) = map(int, input().split())
	s = li()
	t = li()
	q = ii()
	for i in range(q):
		y = ii()
		ans = ''
		ans += str(s[y % n - 1])
		ans += str(t[y % m - 1])
		print(ans)


(a, b) = map(int, input().split())
c = list(map(str, input().split()))
d = list(map(str, input().split()))
e = int(input())
for i in range(e):
	f = int(input())
	r = ''
	if f % a == 0:
		r += c[-1]
	else:
		r += c[f % a - 1]
	if f % b == 0:
		r += d[-1]
	else:
		r += d[f % b - 1]
	print(r)


(n, m) = map(int, input().split())
s = input().split()
t = input().split()
q = int(input())
b = []
for a in range(q):
	c = int(input())
	b.append(s[c % n - 1] + t[c % m - 1])
print('\n'.join(b))


data1 = input()
d1 = data1.split()
n = int(d1[0])
m = int(d1[1])
data2 = input()
data3 = input()
d2 = data2.split()
d3 = data3.split()
q = int(input())
for _ in range(q):
	no = int(input())
	ans = d2[no % n - 1] + d3[no % m - 1]
	print(ans)


(n, m) = map(int, input().split())
s = [i for i in input().split()]
t = [i for i in input().split()]
for i in range(int(input())):
	lis = []
	num = int(input())
	if num < n:
		lis.append(s[num - 1])
	else:
		rem = num % n
		if rem == 0:
			lis.append(s[n - 1])
		else:
			lis.append(s[rem - 1])
	if num < m:
		lis.append(t[num - 1])
	else:
		rem = num % m
		if rem == 0:
			lis.append(t[m - 1])
		else:
			lis.append(t[rem - 1])
	print(''.join(lis))


(n, m) = input().split()
n = int(n)
m = int(m)
a = [x for x in input().split()]
b = [x for x in input().split()]
q = int(input())
for i in range(1, q + 1):
	t = int(input())
	print(a[(t - 1) % n] + b[(t - 1) % m])


from math import ceil
from sys import stdout
import random

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
(n, m) = mi()
s1 = input().split()
s2 = input().split()
i = 0
j = 0
b = []
while 1:
	b.append(s1[i] + s2[j])
	i += 1
	j += 1
	if i == n:
		i = 0
	if j == m:
		j = 0
	if i == 0 and j == 0:
		break
q = ii()
n1 = len(b)
for i in range(q):
	a = ii()
	c = a % n1
	if c == 0:
		print(b[n1 - 1])
	else:
		print(b[c - 1])


read = lambda : list(map(int, input().split(' ')))
n_m = read()
(n, m) = n_m
s = input().split(' ')
t = input().split(' ')
q = int(input())
for i in range(q):
	arg = int(input())
	print(s[arg % n - 1] + t[arg % m - 1])


(n, m) = map(int, input().split())
n1 = str(input())
n2 = n1.split(' ')
m1 = str(input())
m2 = m1.split(' ')
q = int(input())
e = []
for i in range(q):
	k = int(input())
	k1 = k
	k2 = k
	if k1 >= n:
		k1 = k1 % n
	if k2 >= m:
		k2 = k2 % m
	nm = n2[k1 - 1] + m2[k2 - 1]
	e.append(nm)
for j in range(len(e)):
	print(e[j])


(n, m) = map(int, input().split())
s = list(map(str, input().split()))
t = list(map(str, input().split()))
q = int(input())
a = []
for i in range(q):
	y = int(input())
	res = s[(y - 1) % n] + t[(y - 1) % m]
	a = a + [res]
print(*a, sep='\n')


(a, b) = [int(x) for x in input().split()]
l1 = input().split()
l2 = input().split()
n = int(input())
for i in range(n):
	k = int(input())
	p = k % a
	q = k % b
	print(l1[p - 1] + l2[q - 1])


def solution(p, q, r):
	l = []
	for i in r:
		x = i % len(p) - 1
		y = i % len(q) - 1
		l.append(p[x] + q[y])
	return l
(n, m) = map(int, input().split())
nlst = input().split()
mlst = input().split()
q = int(input())
qlst = []
for i in range(q):
	qlst.append(int(input()))
nameslst = solution(nlst, mlst, qlst)
for j in nameslst:
	print(j)


from sys import stdin, stdout
(n, m) = map(int, stdin.readline().strip().split())
s = stdin.readline().strip().split()
s1 = stdin.readline().strip().split()
q = int(input())
for case in range(q):
	y = int(input())
	y -= 1
	print(s[y % n] + s1[y % m])


(n, m) = map(int, input().split())
a = input().split()
b = input().split()
for _ in range(int(input())):
	num = int(input())
	x = num % n - 1
	y = num % m - 1
	s = a[x] + b[y]
	print(s)


(a, b) = map(int, input().split())
ar = list(input().split())
br = list(input().split())
ar.insert(0, ar[-1])
br.insert(0, br[-1])
k = int(input())
for _ in range(k):
	t = int(input())
	s = ar[t % a] + br[t % b]
	print(s)


(n, m) = [int(i) for i in input().split()]
s = input().split()
t = input().split()
q = int(input())
for i in range(q):
	y = int(input())
	yn = y % n
	ym = y % m
	print(s[yn - 1] + t[ym - 1])


nm = input().split(' ')
n = int(nm[0])
m = int(nm[1])
s = input().split(' ')
t = input().split(' ')
sl = len(s)
tl = len(t)
q = int(input())
for i in range(q):
	y = int(input())
	g = y % sl
	h = y % tl
	if g == 0:
		g == sl - 1
	if h == 0:
		h == tl - 1
	print(s[g - 1] + t[h - 1])


string = input().split()
n = int(string[0])
m = int(string[1])
s = input().split()
t = input().split()
k = int(input())
for i in range(k):
	year = int(input()) - 1
	print(s[year % n] + t[year % m])


integers = [int(i) for i in input().split()]
n = integers[0]
m = integers[1]
n_words = input().split()
m_words = input().split()
q = int(input())
word_combos = []
for i in range(q):
	word_combos.append(int(input()))
for i in word_combos:
	print(n_words[i % len(n_words) - 1] + m_words[i % len(m_words) - 1])


(s, t) = list(map(int, input().split(' ')))
list_s = input().split(' ')
list_t = input().split(' ')
qtd = int(input())
for _ in range(qtd):
	num = int(input())
	print(list_s[(num - 1) % s] + '' + list_t[(num - 1) % t])


(n, m) = map(int, input().split())
s = input().split()
t = input().split()
q = int(input())
for i in range(q):
	x = int(input())
	remS = x % n
	remT = x % m
	print(s[remS - 1] + t[remT - 1])


(n, m) = map(int, input().split())
s = list(map(str, input().split()))
t = list(map(str, input().split()))
q = int(input())
for _ in range(q):
	x = int(input())
	x -= 1
	print(s[x % n] + t[x % m])


inp = [int(x) for x in input().split(' ')]
n = inp[0]
m = inp[1]
var1 = [x for x in input().split(' ')]
var2 = [x for x in input().split(' ')]
q = int(input())
lines = []
for i in range(q):
	line = int(input())
	if line:
		lines.append(line)
	else:
		break
for i in lines:
	stri = ''
	stri += var1[(i - 1) % n]
	stri += var2[(i - 1) % m]
	print(stri)


(n, m) = map(int, input().split())
s = list(map(str, input().split()))
t = list(map(str, input().split()))
for _ in range(int(input())):
	y = int(input())
	k = y % (n * m)
	result = s[k % n - 1] + t[k % m - 1]
	print(result)


(n, m) = map(int, input().split(' '))
k = 0
l = 0
li = []
l1 = input().split(' ')
l2 = input().split(' ')
q = int(input())
for i in range(q):
	a = int(input())
	li.append(a)
for i in li:
	r1 = (i - 1) % n
	r2 = (i - 1) % m
	print(l1[r1] + l2[r2])


(n, m) = map(int, input().split())
a = input().split()
b = input().split()
for _ in range(int(input())):
	x = int(input()) - 1
	print(a[x % len(a)] + b[x % len(b)])


(n, m) = map(int, input().split())
str1 = list(map(str, input().split()))
str2 = list(map(str, input().split()))
t = int(input())
for _ in range(t):
	k = int(input())
	print(str1[(k - 1) % len(str1)] + str2[(k - 1) % len(str2)])


(a, b) = map(int, input().split())
x = list(input().split())
y = list(input().split())
for t in range(int(input())):
	h = int(input())
	print(x[h % a - 1] + y[h % b - 1])


a = list(map(int, input().split()))
n = input().split()
s = input().split()
q = int(input())
for i in range(q):
	x = int(input())
	t1 = x % a[0]
	t2 = x % a[1]
	print(n[t1 - 1] + s[t2 - 1])


(n, m) = input('').split()
(n, m) = (int(n), int(m))
words_n = input('').split()
words_m = input('').split()
queries = int(input(''))
names = []
for query in range(0, queries):
	year = int(input())
	index_n = year % n - 1
	index_m = year % m - 1
	name = words_n[index_n] + words_m[index_m]
	names.append(name)
for name in names:
	print(name)


(n, m) = list(map(int, input().split()))
nlist = input().split()
mlist = input().split()
years = int(input())
for i in range(years):
	x = int(input())
	n1 = x % n
	if n1 == 0:
		n1 = n - 1
	else:
		n1 = n1 - 1
	m1 = x % m
	if m1 == 0:
		m1 = m - 1
	else:
		m1 = m1 - 1
	print(nlist[n1] + mlist[m1])


(n, m) = tuple(map(int, input().split()))
s = input().split()
t = input().split()
q = int(input())
for i in range(q):
	req = int(input()) - 1
	print(s[req % n] + t[req % m])


(n, m) = map(int, input().split())
n_v = list(input().split())
m_v = list(input().split())
t = int(input())
for _ in range(t):
	y = int(input()) - 1
	res = n_v[y % len(n_v)] + m_v[y % len(m_v)]
	print(res)


(n, m) = map(int, input().split())
N = list(map(str, input().split()))
M = list(map(str, input().split()))
q = int(input())
for i in range(q):
	y = int(input())
	if y % n == 0 and y % m == 0:
		print(N[n - 1], M[m - 1], sep='')
	elif y % n == 0 and y % m != 0:
		print(N[n - 1], M[y % m - 1], sep='')
	elif y % n != 0 and y % m == 0:
		print(N[y % n - 1], M[m - 1], sep='')
	else:
		print(N[y % n - 1], M[y % m - 1], sep='')


import math
(n, m) = [int(x) for x in input().split()]
nArray = input().split()
mArray = input().split()
q = int(input())
for _ in range(q):
	test = int(input())
	firstIndex = test % n
	firstPart = nArray[firstIndex - 1]
	secondIndex = test % m
	secondPart = mArray[secondIndex - 1]
	print(firstPart + secondPart)


import itertools

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def lcm(a, b):
	return a * b / gcd(a, b)
(n, m) = map(int, input().split(' '))
s1 = list(map(str, input().split(' ')))
s2 = list(map(str, input().split(' ')))
q = int(input())
total_queries = []
for i in range(q):
	total_queries.append(int(input()))
s1 = list(itertools.chain.from_iterable(itertools.repeat(s1, m)))
s2 = list(itertools.chain.from_iterable(itertools.repeat(s2, n)))
final_list = [i + j for (i, j) in zip(s1, s2)]
lcm_ = lcm(n, m)
for i in total_queries:
	i = i % int(lcm_)
	print(final_list[i - 1])


from sys import *
input = stdin.readline
(n, m) = map(int, input().split())
a = list(map(str, input().split()))
b = list(map(str, input().split()))
t = int(input())
for _ in range(t):
	x = int(input())
	p = x % n - 1
	q = x % m - 1
	print(a[p] + b[q])


(n, m) = map(int, input().split())
a = input().split()
b = input().split()
q = int(input())
for i in range(q):
	z = int(input())
	print(a[(z - 1) % n] + b[(z - 1) % m])


(n, m) = map(int, input().split())
a = input().split()
b = input().split()
q = int(input())
while q > 0:
	x = int(input())
	x -= 1
	print(a[x % n] + b[x % m])
	q -= 1


x = list(map(int, input().split()))
y = input().split()
z = input().split()
q = int(input())
l = []
for i in range(q):
	l.append(int(input()))
a = ''
for i in l:
	a += y[i % x[0] - 1]
	a += z[i % x[1] - 1]
	print(a)
	a = ''


(n, m) = map(int, input().split())
s = input()
t = input()
s1 = [s]
t1 = [t]

def convert(lst):
	return lst[0].split()
l1 = convert(s1)
l2 = convert(t1)
len1 = len(l1)
len2 = len(l2)
(l3, l4) = ([], [])
q = int(input())
while q:
	q1 = int(input())
	x = q1 // len1
	index1 = q1 - x * len1
	y = q1 // len2
	index2 = q1 - y * len2
	l3.append(l1[index1 - 1] + l2[index2 - 1])
	q = q - 1
for i in l3:
	print(i)


(m, n) = list(map(int, input().split()))
a = input().split()
length_a = len(a)
b = input().split()
length_b = len(b)
c = int(input())
for i in range(c):
	q = int(input()) - 1
	print(a[q % length_a] + b[q % length_b])


(n, m) = list(map(int, input().split()))
s1 = list(map(str, input().split()))
s2 = list(map(str, input().split()))
q = int(input())
for i in range(q):
	y = int(input())
	j = y % n - 1
	k = y % m - 1
	ans = s1[j] + s2[k]
	print(ans)


(n, m) = map(int, input().split())
s = input().split()
t = input().split()
q = int(input())
while q:
	q = q - 1
	y = int(input())
	left = y % len(s)
	if left == 0:
		left = len(s) - 1
	else:
		left = left - 1
	right = y % len(t)
	if right == 0:
		right = len(t) - 1
	else:
		right = right - 1
	print(s[left] + t[right])


(n, m) = map(int, input().split())
s = list(map(str, input().split()))
s.insert(0, s.pop())
t = list(map(str, input().split()))
t.insert(0, t.pop())
p = int(input())
for i in range(p):
	k = int(input())
	i = k % n
	j = k % m
	print(s[i] + t[j])


(n, m) = input().split()
s = input().split()
t = input().split()
years = int(input())
res = []
while years != 0:
	years -= 1
	temp = int(input())
	res.append(s[temp % int(n) - 1] + t[temp % int(m) - 1])
for year in res:
	print(year)


(n, m) = map(int, input().split())
A = list(input().split())
B = list(input().split())
q = int(input())
for i in range(q):
	x = int(input())
	print(A[(x - 1) % n] + B[(x - 1) % m])


(n, m) = list(map(int, input().split()))
s = list(input().split())
t = list(input().split())
q = int(input())
for i in range(q):
	temp = int(input())
	in_s = n - 1 if temp % n == 0 else temp % n - 1
	in_t = m - 1 if temp % m == 0 else temp % m - 1
	name = s[in_s] + t[in_t]
	print(name)


import sys
from math import gcd
from heapq import heappop
from heapq import heappush
from heapq import heapify
from bisect import insort
from bisect import bisect_right
from bisect import bisect_left
from sys import stdin, stdout
from collections import defaultdict, deque
from math import log2, ceil, floor
inp = lambda : int(input())
sip = lambda : input()
mulip = lambda : map(int, input().split())
lst = lambda : list(map(int, input().split()))
slst = lambda : list(sip())
arr2d = lambda x: [[int(j) for j in input().split()] for i in range(x)]
odds = lambda l: len(list(filter(lambda x: x % 2 != 0, l)))
evens = lambda l: len(list(filter(lambda x: x % 2 == 0, l)))
mod = pow(10, 9) + 7
Judge = 0
if Judge:
	sys.stdin = open('input.in', 'r')
(n, m) = mulip()
s = [str(x) for x in input().split()]
t = [str(x) for x in input().split()]
q = inp()
for i in range(q):
	x = inp()
	a = x % n
	b = x % m
	print(s[a - 1] + t[b - 1])


import sys, math
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())
t = 1
for tt in range(t):
	(n, m) = invr()
	q = list(map(str, input().split()))
	w = list(map(str, input().split()))
	qw = inp()
	a = []
	for i in range(qw):
		qwqw = inp()
		print(q[(qwqw - 1) % n] + w[(qwqw - 1) % m])


(n, m) = map(int, input().split())
s = list(map(str, input().split()))
t = list(map(str, input().split()))
c = 0
c1 = 0
ll = []
ln = n * m
cnt = 0
while ln > cnt:
	ll.append(s[c] + t[c1])
	cnt += 1
	c += 1
	c1 += 1
	if c >= n:
		c = 0
	if c1 >= m:
		c1 = 0
q = int(input())
for i in range(q):
	x = int(input())
	x = (x - 1) % ln
	print(ll[x])


a = input('').split(' ')
import math
n = int(a[0])
m = int(a[1])
s = input('').split(' ')
t = input('').split(' ')
q = int(input(''))
hg = n * m // math.gcd(n, m)
i = 0
c = 0
j = 0
ans = []
while c < hg:
	ans.append(s[i] + t[j])
	c = c + 1
	i = (i + 1) % n
	j = (j + 1) % m
for i in range(q):
	d = int(input(''))
	print(ans[(d - 1) % hg])


(n, m) = map(int, input().split())
l1 = list(map(str, input().split()))
l2 = list(map(str, input().split()))
e = int(input())
while e > 0:
	i = int(input())
	print(l1[i % n - 1] + l2[i % m - 1])
	e -= 1


_ = input()
part1 = input().split()
part2 = input().split()
n = int(input())
inp = [int(input()) for _ in range(n)]
for i in inp:
	print(part1[i % len(part1) - 1] + part2[i % len(part2) - 1])


(n, m) = map(int, input().split())
str1 = list(map(str, input().split()))
str2 = list(map(str, input().split()))
q = int(input())
for i in range(q):
	a = int(input())
	print(str1[(a - 1) % n] + str2[(a - 1) % m])


(n, m) = map(int, input('').split())
N = list(input('').split())
M = list(input('').split())
q = int(input(''))
YEAR = []
for i in range(q):
	YEAR.append(int(input('')))
RESULT = []
for i in YEAR:
	tempn = i % n
	tempm = i % m
	print(N[tempn - 1] + M[tempm - 1])


(m1, n1) = input().split()
m = int(m1)
n = int(n1)
s = list(map(str, input().split()))
t = list(map(str, input().split()))
p = int(input())
for i in range(p):
	war = ''
	k = int(input())
	war += s[k % m - 1]
	war += t[k % n - 1]
	print(war)


(n, m) = map(int, input().split())
s = [x for x in input().split(' ')]
t = [x for x in input().split(' ')]
q = int(input())
while q != 0:
	y = int(input())
	print(s[(y - 1) % n] + t[(y - 1) % m])
	q -= 1


(l, m) = map(int, input().split())
dic1 = input().split()
dic2 = input().split()
a = []
for i in range(int(input())):
	inp = int(input())
	j = inp % l
	r = inp % m
	if j == 0:
		j = len(dic1)
	if r == 0:
		r = len(dic2)
	a.append(dic1[j - 1] + dic2[r - 1])
for i in a:
	print(i)


from sys import stdin, stdout, stderr
from functools import lru_cache
import math

def read():
	return stdin.readline().rstrip()

def readint():
	return int(read())

def main():
	(n, m) = list(map(int, read().split()))
	s = read().split()
	t = read().split()
	for x in range(readint()):
		year = readint()
		print(str(s[year % n - 1]) + str(t[year % m - 1]))
main()


(n, m) = [int(i) for i in input().split()]
x = [i for i in input().split()]
y = [i for i in input().split()]
q = int(input())
liste_year = []
for i in range(q):
	liste_year.append(int(input()))
for i in range(q):
	print(str(x[liste_year[i] % n - 1]) + str(y[liste_year[i] % m - 1]))


(n, m) = map(int, input().split())
(n_strings, m_strings) = (input().split(), input().split())
for q in range(0, int(input())):
	y = int(input())
	yn = y % n - 1
	ym = y % m - 1
	print(n_strings[yn] + m_strings[ym])


(n, m) = map(int, input().split())
a = list(map(str, input().split()))
b = list(map(str, input().split()))
c = int(input())
for i in range(c):
	d = int(input())
	print(a[(d - 1) % n] + b[(d - 1) % m])


(a, b) = list(map(int, input().split()))
aa = input().split()
bb = input().split()
for _ in range(int(input())):
	i = int(input()) - 1
	print('{}{}'.format(aa[i % a], bb[i % b]))


s = input().split()
n = int(s[0])
m = int(s[1])
s1 = input().split()
s2 = input().split()
for i in range(int(input())):
	t = int(input()) - 1
	a = t % n
	b = t % m
	print(s1[a] + s2[b])


in1 = input().split()
l1 = int(in1[0])
l2 = int(in1[1])
s1 = input().split()
s2 = input().split()
in2 = int(input())
for i in range(in2):
	in3 = int(input())
	a = in3 % l1 - 1
	b = in3 % l2 - 1
	s = s1[a] + s2[b]
	print(s)


(n, m) = [int(x) for x in input().split()]
a = input().split()
b = input().split()
n = int(input())
for i in range(n):
	y = int(input())
	i = int(y % len(a))
	j = int(y % len(b))
	print(a[i - 1] + b[j - 1])


(n, m) = input().split()
n = int(n)
m = int(m)
s = str(input())
t = str(input())
s = s.split(' ')
t = t.split(' ')
for i in range(int(input())):
	val = int(input())
	print(s[val % n - 1] + t[val % m - 1])


x = [int(i) for i in input().split()]
(m, n) = (x[0], x[1])
y = input().split()
z = input().split()
p = int(input())
for _ in range(p):
	idx = int(input())
	print(y[idx % m - 1] + z[idx % n - 1])


nm = input()
i = 0
while nm[i] != ' ':
	i += 1
n = int(nm[0:i])
m = int(nm[i:])

def space_separate_to_list():
	s_ = str(input())
	s_spaces = [-1]
	for i in range(len(s_)):
		if s_[i] == ' ':
			s_spaces.append(i)
	s_spaces.append(len(s_))
	s = []
	for i in range(len(s_spaces) - 1):
		s.append(s_[s_spaces[i] + 1:s_spaces[i + 1]])
	return s
s = space_separate_to_list()
t = space_separate_to_list()
q = int(input())
j = 0
year = []
while j < q:
	year.append(int(input()))
	j += 1
for i in year:
	s_mod_n = (i - 1) % n
	t_mod_n = (i - 1) % m
	print(s[s_mod_n] + t[t_mod_n])


(n, m) = [int(x) for x in input().split()]
a = [x for x in input().split()]
b = [x for x in input().split()]
x = int(input())
for i in range(x):
	k = int(input())
	k -= 1
	print(a[k % n] + b[k % m])


(n, m) = map(int, input().split())
a = input().split()
b = input().split()
q = int(input())
while q:
	q -= 1
	n = int(input()) - 1
	print(a[n % len(a)] + b[n % len(b)])


(n, m) = map(int, input().split())
sstr = input().split()
tstr = input().split()
q = int(input())
for y in [int(input()) for _ in range(q)]:
	s = y - n * (y // n) - 1
	t = y - m * (y // m) - 1
	print(sstr[s] + tstr[t])


k = []
(n, m) = map(int, input().split())
s = list(input().split())
t = list(input().split())
for _ in range(int(input())):
	y = int(input())
	k.append(s[y % n - 1] + t[y % m - 1])
for i in k:
	print(i)


inp = input()
(n, m) = [int(c) for c in inp.split()]
inp = input()
a = [c for c in inp.split()]
inp = input()
b = [c for c in inp.split()]
q = int(input())
for i in range(q):
	yr = int(input())
	str = a[(yr - 1) % n] + b[(yr - 1) % m]
	print(str)


from sys import stdin, stdout
from math import gcd

def lcm(a, b):
	return abs(a * b) // gcd(a, b)
s = stdin.readline().strip().split(' ')
(m, n) = (int(s[0]), int(s[1]))
lcm = lcm(m, n)
s1 = stdin.readline().strip().split(' ')
s2 = stdin.readline().strip().split(' ')
ms = s1 * (lcm // m)
ns = s2 * (lcm // n)
lu = {}
for i in range(1, lcm + 1):
	lu[i] = ms[i - 1] + ns[i - 1]
q = int(stdin.readline())
while q:
	q -= 1
	a = int(stdin.readline())
	mo = a % lcm
	if mo == 0:
		mo = lcm
	stdout.write(lu[mo] + '\n')


e = input().split()
(n, m) = (int(e[0]), int(e[1]))
s = input().split()
t = input().split()
for i in range(int(input())):
	z = int(input()) - 1
	print(s[z % n] + t[z % m])


(n, m) = map(int, input().split())
n1 = list(map(str, input().split()))
m1 = list(map(str, input().split()))
q = int(input())
for i in range(q):
	t = int(input())
	print(n1[t % n - 1] + m1[t % m - 1])


(n, m) = map(int, input().split())
mass1 = []
mass2 = []
mass1 = input().split()
mass2 = input().split()
q = int(input())
for i in range(q):
	now = int(input())
	print(mass1[(now - 1) % n] + mass2[(now - 1) % m])


(n, m) = map(int, input().split())
s = list(input().split(' '))
t = list(input().split(' '))
q = int(input())
l = []
i = 0
j = 0
count = 0
while count < n * m:
	l.append(s[i] + t[j])
	if i == n - 1:
		i = -1
	if j == m - 1:
		j = -1
	i += 1
	j += 1
	count += 1
for i in range(q):
	z = int(input())
	z = z % (n * m)
	print(l[z - 1])


(n, m) = [int(s) for s in input().split()]
a = [s for s in input().split()]
b = [s for s in input().split()]
q = int(input())
for i in range(q):
	n = int(input())
	print(a[(n - 1) % len(a)] + b[(n - 1) % len(b)])


(a, b) = list(map(int, input().split()))
c = dict(zip(range(1, a + 1), input().split()))
d = dict(zip(range(1, b + 1), input().split()))
for _ in ' ' * int(input()):
	z = int(input())
	s = z % a if z % a != 0 else a
	f = z % b if z % b != 0 else b
	print(c[s] + d[f])


(n, m) = map(int, input().split())
s1 = input().split()
s2 = input().split()
for t in range(int(input())):
	y = int(input()) - 1
	print(s1[y % n] + s2[y % m])


(N, M) = map(int, input().split())
xs = input().split()
ys = input().split()
Q = int(input())
for _ in range(Q):
	q = int(input())
	print(xs[q % N - 1].strip() + ys[q % M - 1].strip())


(a, b) = [int(tmp) for tmp in input().split()]
s = input().split()
p = input().split()
t = int(input())
for i in range(t):
	k = 0
	l = 0
	x = int(input())
	if x % a == 0:
		k = a
	else:
		k = x % a
	if x % b == 0:
		l = b
	else:
		l = x % b
	print(''.join(map(str, s[k - 1] + p[l - 1])))


(x, y) = input().split(' ')
x = int(x)
y = int(y)
s = ''
s1 = ''
s = input().split(' ')
s1 = input().split(' ')
q = int(input())
for i in range(q):
	z = int(input())
	print(s[(z - 1) % x] + s1[(z - 1) % y])


(n, m) = map(int, input().split())
a = list(input().split())
b = list(input().split())
for _ in range(int(input())):
	tc = int(input())
	print(a[tc % n - 1], b[tc % m - 1], sep='')


l = list(map(int, input().split()))
s1 = list(map(str, input().split()))
s2 = list(map(str, input().split()))
q = int(input())
n = l[0]
m = l[1]
a = n * m
while q:
	yr = int(input())
	if yr > a:
		yr = yr % a
	y1 = yr % n
	y2 = yr % m
	if y1 == 0:
		y1 = n
	if y2 == 0:
		y2 = m
	ans = s1[y1 - 1] + s2[y2 - 1]
	print(ans)
	q -= 1


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def main():
	(n, m) = LI()
	a = LS()
	b = LS()
	t = I()
	rr = []
	for _ in range(t):
		y = I() - 1
		rr.append(JA([a[y % n], b[y % m]], ''))
	return JA(rr, '\n')
print(main())


(l1, l2) = map(int, input().split())
s1 = input().split()
s2 = input().split()
q = int(input())
while q:
	n = int(input())
	print(s1[(n - 1) % l1] + s2[(n - 1) % l2])
	q -= 1


(a, b) = map(int, input().split())
s = list(map(str, input().split()))
t = list(map(str, input().split()))
q = int(input())
for _ in range(q):
	pa = int(input())
	print(s[pa % a - 1] + t[pa % b - 1])


input()
w1 = input().split()
w2 = input().split()
n = int(input())
for i in range(n):
	a = int(input()) - 1
	print(w1[a % len(w1)] + w2[a % len(w2)])


(n, m) = map(int, input().split())
s = []
s += input().split()
t = []
t += input().split()
q = int(input())
for i in range(q):
	year = int(input())
	s_index = year % n
	t_index = year % m
	print(s[s_index - 1] + t[t_index - 1])


from sys import stdin, stdout
import bisect
import math

def st():
	return list(stdin.readline().strip())

def inp():
	return int(stdin.readline())

def li():
	return list(map(int, stdin.readline().split()))

def mp():
	return map(int, stdin.readline().split())

def pr(n):
	stdout.write(str(n) + '\n')

def soe(limit):
	l = [1] * (limit + 1)
	prime = []
	for i in range(2, limit + 1):
		if l[i]:
			for j in range(i * i, limit + 1, i):
				l[j] = 0
	for i in range(2, limit + 1):
		if l[i]:
			prime.append(i)
	return prime

def segsoe(low, high):
	limit = int(high ** 0.5) + 1
	prime = soe(limit)
	n = high - low + 1
	l = [0] * (n + 1)
	for i in range(len(prime)):
		lowlimit = low // prime[i] * prime[i]
		if lowlimit < low:
			lowlimit += prime[i]
		if lowlimit == prime[i]:
			lowlimit += prime[i]
		for j in range(lowlimit, high + 1, prime[i]):
			l[j - low] = 1
	for i in range(low, high + 1):
		if not l[i - low]:
			if i != 1:
				print(i)

def power(a, n):
	r = 1
	while n:
		if n & 1:
			r = r * a
			n = n - 1
		else:
			a = a * a
			n = n >> 1
	return r

def solve():
	(n, m) = mp()
	a = input().split()
	b = input().split()
	q = inp()
	for i in range(q):
		x = inp()
		(p, q) = (x % n, x % m)
		if p != 0 and q != 0:
			print(a[p - 1] + b[q - 1])
		elif p == 0 and q != 0:
			print(a[-1] + b[q - 1])
		elif p != 0 and q == 0:
			print(a[p - 1] + b[-1])
		else:
			print(a[-1] + b[-1])
for _ in range(1):
	solve()


(n, m) = map(int, input().split())
a = list(input().split(maxsplit=n))
b = list(input().split(maxsplit=m))
q = int(input())
list_years = []
for i in range(q):
	list_years.append(int(input()))
list_result = []
len_a = len(a)
len_b = len(b)
while len(list_years) > 0:
	year = list_years.pop(0)
	if year <= len_a - 1 and year <= len_b - 1:
		list_result.append(a[year - 1] + b[year - 1])
	elif year <= len_a - 1 and year > len_b:
		index_a = year
		index_b = year % len_b
		list_result.append(a[index_a - 1] + b[index_b - 1])
	elif year > len_a - 1 and year <= len_b:
		index_b = year
		index_a = year % len_a
		list_result.append(a[index_a - 1] + b[index_b - 1])
	else:
		index_a = year % len_a
		index_b = year % len_b
		list_result.append(a[index_a - 1] + b[index_b - 1])
for item in list_result:
	print(item)


line = input()
n = int(line.split(' ')[0])
m = int(line.split(' ')[1])
nline = input()
n_arr = nline.split(' ')
mline = input()
m_arr = mline.split(' ')
desired_years = []
how_many = int(input())
for i in range(how_many):
	desired_years.append(int(input()))
for i in desired_years:
	print(n_arr[(i - 1) % n] + m_arr[(i - 1) % m])


(N, M) = map(int, input().split())
SS = input().split()
TS = input().split()
q = int(input())
for i in range(q):
	y = int(input()) - 1
	print(SS[y % N] + TS[y % M])


(n, m) = map(int, input().split())
s = list(input().split())
t = list(input().split())
q = int(input())
for i in range(q):
	num = int(input())
	print(s[(num - 1) % n] + t[(num - 1) % m])


(n, m) = map(int, input().split())
t = input().split()
s = input().split()
q = int(input())
q_list = [int(input()) for _ in range(q)]
for qq in q_list:
	qq -= 1
	print(t[qq % n] + s[qq % m])


a = input().split()
n = int(a[0])
m = int(a[1])
s = input().split()
t = input().split()
q = int(input())
for i in range(q):
	y = int(input())
	n1 = y % n
	m1 = y % m
	print(s[n1 - 1] + t[m1 - 1])


strinput = list(map(int, input().split()))
st1 = list(input().split())
st2 = list(input().split())
q = int(input())
inputlist = []
count = 1
while count <= q:
	x = int(input())
	inputlist.append(x)
	count += 1

def st1check(x):
	if x <= len(st1):
		return st1[x - 1]
	else:
		return st1[x % len(st1) - 1]

def st2check(x):
	if x <= len(st2):
		return st2[x - 1]
	else:
		return st2[x % len(st2) - 1]
for i in inputlist:
	print(st1check(i) + st2check(i))


(n1, n2) = map(int, input().split())
a = list(map(str, input().split()))
b = list(map(str, input().split()))
q = int(input())
for _ in range(q):
	n = int(input())
	n3 = (n - 1) % n1
	n4 = (n - 1) % n2
	s = ''
	s += a[n3]
	s += b[n4]
	print(s)


(m, n) = [int(x) for x in input().split(' ')]
s1 = [x for x in input().split(' ')]
s2 = [x for x in input().split(' ')]
q = int(input())
for _ in range(q):
	year = int(input())
	(a, b) = ((year - 1) % m, (year - 1) % n)
	print(s1[a] + s2[b])


(n, m) = map(int, input().split())
s1 = list(input().split())
s2 = list(input().split())
k = int(input())
a = []
for j in range(k):
	s = int(input())
	c = s % n
	a.append(s1[c - 1])
	b = s % m
	a.append(s2[b - 1])
	l = ''.join(a)
	print(l)
	a = []


(n, m) = map(int, input().split())
list1 = [x for x in input().split()]
list2 = [x for x in input().split()]
N = int(input())
for _ in range(0, N):
	num = int(input())
	print(list1[num % len(list1) - 1] + list2[num % len(list2) - 1])


(n, m) = map(int, input().split(' '))
n = [str(x) for x in input().split(' ')]
m = [str(x) for x in input().split(' ')]
q = int(input())
(a, b) = (len(n), len(m))
for x in range(q):
	inp = int(input())
	print(n[inp % a - 1] + m[inp % b - 1])


import sys
(N, M) = [int(i) for i in sys.stdin.readline().strip().split(' ')]
T1 = sys.stdin.readline().strip().split(' ')
T2 = sys.stdin.readline().strip().split(' ')
T = int(sys.stdin.readline().strip())
for _ in range(T):
	n = int(sys.stdin.readline().strip()) - 1
	print(T1[n % len(T1)] + T2[n % len(T2)])


(z, u) = input().split()
z = int(z)
u = int(u)
e = input().split()
r = input().split()
u = int(input())
l = []
for x in range(u):
	l.append(int(input()))
for x in range(u):
	p = l[x]
	q = l[x]
	while p > 10000000 * len(e):
		p = p - 10000000 * len(e)
	while p > 1000000 * len(e):
		p = p - 1000000 * len(e)
	while p > 100000 * len(e):
		p = p - 100000 * len(e)
	while p > 10000 * len(e):
		p = p - 10000 * len(e)
	while p > 1000 * len(e):
		p = p - 1000 * len(e)
	while p > 100 * len(e):
		p = p - 100 * len(e)
	while p > len(e):
		p = p - len(e)
	while q > 10000000 * len(r):
		q = q - 10000000 * len(r)
	while q > 1000000 * len(r):
		q = q - 1000000 * len(r)
	while q > 100000 * len(r):
		q = q - 100000 * len(r)
	while q > 10000 * len(r):
		q = q - 10000 * len(r)
	while q > 1000 * len(r):
		q = q - 1000 * len(r)
	while q > 100 * len(r):
		q = q - 100 * len(r)
	while q > len(r):
		q = q - len(r)
	print(e[p - 1] + r[q - 1])


(n, m) = list(map(int, input().split()))
s = []
s = list(map(str, input().split()))
t = list(map(str, input().split()))
q = int(input())
i = 0
j = 0
while q:
	y = int(input())
	i = (y - 1) % n
	j = (y - 1) % m
	p = ''
	p = s[i] + t[j]
	print(p)
	q = q - 1


input()
f = list(map(str, input().split()))
s = list(map(str, input().split()))
q = int(input())
a = [next(map(int, input().split())) for i in range(q)]
for i in a:
	print(f[i % len(f) - 1] + s[i % len(s) - 1])


(n, m) = map(int, input().split())
a = [x for x in input().split()]
b = [x for x in input().split()]
q = int(input())
s = []
for x in range(q):
	y = int(input())
	s.append(str(a[(y - 1) % n] + b[(y - 1) % m]))
for i in s:
	print(i)


def inp(dtype=str, strip=True):
	s = input()
	res = [dtype(p) for p in s.split()]
	res = res[0] if len(res) == 1 and strip else res
	return res

def problem1():
	(n, m) = inp(int)
	s = inp(strip=False)
	t = inp(strip=False)
	q = inp(int)
	for _ in range(q):
		y = inp(int) - 1
		print(s[y % n] + t[y % m])

def problem2():
	pass

def problem3():
	pass

def problem4():
	pass

def problem5():
	pass
problem1()


(N, M) = map(int, input().split())
s1 = input().split()
s2 = input().split()
for x in range(int(input())):
	num = int(input())
	print(s1[num % N - 1] + s2[num % M - 1])


(length1, length2) = map(int, input().split())
s1 = list(map(str, input().split()))
s2 = list(map(str, input().split()))
nn = int(input())
for x in range(nn):
	a = int(input()) - 1
	x1 = a % length1
	x2 = a % length2
	print(s1[x1] + s2[x2])
	del a


(n, m) = map(int, input().split())
s = list(map(str, input().split()))
t = list(map(str, input().split()))
num = int(input())
for i in range(num):
	x = int(input())
	print(s[x % n - 1] + t[x % m - 1])


a = list(map(int, input().split()))
s = input().split()
t = input().split()
n = int(input())
for i in range(0, n):
	b = int(input())
	pos1 = 0
	pos2 = 0
	if b % a[0] == 0 and b % a[1] != 0:
		pos1 = a[0] - 1
		pos2 = b % a[1] - 1
	elif b % a[1] == 0 and b % a[0] != 0:
		pos2 = a[1] - 1
		pos1 = b % a[0] - 1
	elif b % a[1] == 0 and b % a[0] == 0:
		pos2 = a[1] - 1
		pos1 = a[0] - 1
	else:
		pos1 = b % a[0] - 1
		pos2 = b % a[1] - 1
	print(s[pos1] + t[pos2])


(n, m) = map(int, input().split())
l1 = list(input().split())
l2 = list(input().split())
q = int(input())
for _ in range(q):
	cur = int(input()) - 1
	print(l1[cur % n] + l2[cur % m])


(n, m) = list(map(int, input().split()))
l1 = list(map(str, input().split()))
l2 = list(map(str, input().split()))
year = []
i = 0
j = 0
for _ in range(n * m):
	if i == n:
		i = 0
	if j == m:
		j = 0
	el1 = l1[i]
	el2 = l2[j]
	total = el1 + el2
	year.append(total)
	i += 1
	j += 1
q = int(input())
for k in range(q):
	i = int(input())
	print(year[i % (n * m) - 1])


(n, m) = map(int, input().split())
s = list(input().split())
t = list(input().split())
for i in range(int(input())):
	k = []
	a = int(input())
	if a < n:
		k.append(s[a - 1])
	else:
		k.append(s[a % n - 1])
	if a < m:
		k.append(t[a - 1])
	else:
		k.append(t[a % m - 1])
	print(k[0] + k[1])


(a, b) = input().split()
a = int(a)
b = int(b)
o = input()
o1 = input()
l1 = o.split()
l2 = o1.split()
ss = int(input())
for i in range(ss):
	f = int(input())
	print(l1[f % a - 1], end='')
	print(l2[f % b - 1])


def newyear(n, m, s, t, y):
	if y % m == 0 and y % n == 0:
		print(s[n - 1] + t[m - 1])
	elif y % m == 0:
		print(s[y % n - 1] + t[m - 1])
	elif y % n == 0:
		print(s[n - 1] + t[y % m - 1])
	else:
		print(s[y % n - 1] + t[y % m - 1])
z = input().split()
n = int(z[0])
m = int(z[1])
s = input().split()
t = input().split()
q = int(input())
for i in range(q):
	y = int(input())
	newyear(n, m, s, t, y)


(n, m) = map(int, input().split())
lst_n = input().split()
lst_m = input().split()
for i in range(int(input())):
	a = int(input()) - 1
	print(lst_n[a % n] + lst_m[a % m])


(a, b) = input().split()
a = int(a)
b = int(b)
c = input().split()
d = input().split()
e = input()
e = int(e)
while e > 0:
	god = input()
	god = int(god)
	n_el_1 = god % a
	n_el_2 = god % b
	el_1 = c[n_el_1 - 1]
	el_2 = d[n_el_2 - 1]
	print(el_1 + el_2)
	e = e - 1
	god = 0


(n, m) = map(int, input().split())
f = input().split(' ')
s = input().split(' ')
q = int(input())
while q > 0:
	x = int(input())
	print(f[x % n - 1] + s[x % m - 1])
	q -= 1


n = input()
k = n.find(' ')
l = k
k = int(n[:l])
n = n[l + 1:]
l = int(n)
n = k
m = l
s = input()
t = input()
list1 = []
list2 = []
while s.count(' '):
	p = s.find(' ')
	q = p
	p = s[:p]
	list1.append(p)
	s = s[q + 1:]
list1.append(s)
while t.count(' '):
	p = t.find(' ')
	q = p
	p = t[:p]
	list2.append(p)
	t = t[q + 1:]
list2.append(t)
q = int(input())
i = 0
while i < q:
	y = int(input())
	print(list1[(y - 1) % n], end='')
	print(list2[(y - 1) % m])
	i += 1


(n, m) = map(int, input().split())
A = input().split()
B = input().split()
q = int(input())
for i in range(q):
	y = int(input())
	print(A[(y % n + n - 1) % n] + B[(y % m + m - 1) % m])


(n, m) = [int(i) for i in input().split()]
w1 = input().split()
w2 = input().split()
for _ in range(int(input())):
	y = int(input())
	print(w1[y % n - 1] + w2[y % m - 1])


q = lambda : map(int, input().split())
qs = lambda : input().split()
(n, m) = q()
a = list(qs())
b = list(qs())
for _ in range(int(input())):
	(x,) = q()
	print(a[x % n - 1] + b[x % m - 1])


(x, y) = map(int, input().split())
s1 = list(map(str, input().split()))
s2 = list(map(str, input().split()))
for i in range(int(input())):
	a = int(input())
	print(s1[a % x - 1], s2[a % y - 1], sep='')


import sys
import math
a = list(map(int, input('').strip().split()))[:2]
s = input().split()
t = input().split()
q = int(input())
for i in range(q):
	x = int(input())
	print(str(s[x % a[0] - 1]) + str(t[x % a[1] - 1]))


(n, m) = list(map(int, input().split()))
s = input().split()
t = input().split()
for i in range(int(input())):
	a = int(input())
	print(s[a % n - 1] + t[a % m - 1])


(m, n) = list(map(int, input().split()))
S1 = input().split()
S2 = input().split()
for _ in range(int(input())):
	Y = int(input())
	print(S1[(Y - 1) % m] + S2[(Y - 1) % n])


(n, m) = map(int, input().split(' '))
string1 = list(map(str, input().split(' ')))
string2 = list(map(str, input().split(' ')))
q = int(input())
for i in range(q):
	a = int(input())
	if a <= n and a <= m:
		concatenate = string1[a - 1] + string2[a - 1]
		print(concatenate)
	elif a <= n and a > m:
		value = a % m
		concatenate = string1[a - 1] + string2[value - 1]
		print(concatenate)
	elif a > n and a <= m:
		value = a % n
		concatenate = string1[value - 1] + string2[a - 1]
		print(concatenate)
	elif a > n and a > m:
		value = a % n
		value1 = a % m
		concatenate = string1[value - 1] + string2[value1 - 1]
		print(concatenate)


(n, m) = [int(i) for i in input().split()]
a = input().split()
b = input().split()
t = int(input())
for _ in range(t):
	y = int(input())
	if y > n:
		x = y % n - 1
	else:
		x = y - 1
	if y > m:
		z = y % m - 1
	else:
		z = y - 1
	print(a[x] + b[z])


(n, m) = list(map(int, input().split()))
l1 = input().split()
l2 = input().split()
ans = []

def get_year(year, l1, l2, n, m):
	year -= 1
	return l1[year % n] + l2[year % m]
x = int(input())
for i in range(x):
	ans.append(get_year(int(input()), l1, l2, n, m))
print('\n'.join(ans))


(x, y) = map(int, input().split())
p = list(map(str, input().split()))
k = list(map(str, input().split()))
for _ in range(int(input())):
	a = int(input())
	print(p[(a - 1) % x] + k[(a - 1) % y])


ok = [int(x) for x in input().split()]
f = [x for x in input().split()]
g = [x for x in input().split()]
q = int(input())
for i in range(q):
	t = int(input()) - 1
	print(f[t % ok[0]] + g[t % ok[1]])


(n, m) = [int(i) for i in input().split()]
n_str = input().split()
m_str = input().split()
q = int(input())
queries = []
while q > 0:
	queries.append(int(input()))
	q = q - 1
for i in queries:
	print('%s%s' % (n_str[(i - 1) % n], m_str[(i - 1) % m]))


import sys

def my_strip(string):
	return string[:-1]
(n, m) = map(int, sys.stdin.readline().split())
n_string = sys.stdin.readline().split()
m_string = sys.stdin.readline().split()
q = list(map(int, list(map(my_strip, sys.stdin.readlines()))))

def naming(n, m, n_string, m_string, q):
	for i in range(1, len(q)):
		print(n_string[(q[i] - 1) % len(n_string)] + m_string[(q[i] - 1) % len(m_string)])
naming(n, m, n_string, m_string, q)


(n, m) = [int(n) for n in input().split()]
n_strings = [s for s in input().split()]
m_strings = [t for t in input().split()]
q = int(input())
for query in range(q):
	y = int(input())
	if y > n:
		first_part = n_strings[y % n - 1]
	else:
		first_part = n_strings[y - 1]
	if y > m:
		second_part = m_strings[y % m - 1]
	else:
		second_part = m_strings[y - 1]
	print(first_part + second_part)


(n, m) = map(int, input().split())
la = list(map(str, input().split()))
lb = list(map(str, input().split()))
for i in range(int(input())):
	yr = int(input())
	print(la[yr % n - 1] + lb[yr % m - 1])


input()
G = input().split()
Z = input().split()
N = int(input())
while N > 0:
	yy = int(input()) - 1
	Gi = yy % len(G)
	Zi = yy % len(Z)
	print(G[Gi] + Z[Zi])
	N -= 1


def solve(inp, n, s, t):
	ans = []
	for i in inp:
		pre = s[(i - 1) % n[0]]
		post = t[(i - 1) % n[1]]
		ans.append(pre + post)
	return '\n'.join(ans)
n = tuple([int(i) for i in input().split()])
s = input().split()
t = input().split()
k = int(input())
inp = []
for i in range(k):
	inp.append(int(input()))
print(solve(inp, n, s, t))


(n, m) = map(int, input().split())
a = input().split()
b = input().split()
q = int(input())
for k in range(q):
	y = int(input())
	print(a[y % n - 1] + b[y % m - 1])


(n, m) = map(int, input().split())
l1 = list(map(str, input().split()))
l2 = list(map(str, input().split()))
q = int(input())
for _ in range(q):
	t = int(input())
	t -= 1
	print(l1[t % n] + l2[t % m])


(n, m) = map(int, input().split())
ss = input().split()
ts = input().split()
for _ in range(int(input())):
	y = int(input()) - 1
	print(ss[y % n] + ts[y % m])


(n, m) = map(int, input().split())
l1 = list(input().split())
l2 = list(input().split())
q = int(input())
for i in range(q):
	n = int(input())
	if n <= len(l1) and n <= len(l2):
		print(l1[n - 1] + l2[n - 1])
	else:
		r1 = n % len(l1)
		if r1 > 0:
			print(l1[r1 - 1], end='')
		else:
			print(l1[-1], end='')
		r2 = n % len(l2)
		if r2 > 0:
			print(l2[r2 - 1], end='')
		else:
			print(l2[-1], end='')
		print('')


(n, m) = input().split()
n = int(n)
m = int(m)
s = input().split()
t = input().split()
q = int(input())
qin = []
for x in range(q):
	qin.append(int(input()))
for y in qin:
	print(s[y % n - 1] + t[y % m - 1])


(n, k) = map(int, input().split())
a = input().split()
b = input().split()
t = int(input())
for _ in range(t):
	nn = int(input())
	new_a = nn % n
	new_b = nn % k
	print(a[new_a - 1] + b[new_b - 1])


(n, m) = map(int, input().split())
s = list(map(str, input().split()))
t = list(map(str, input().split()))
for _ in range(int(input())):
	q = int(input())
	a = q % n
	b = q % m
	if a == 0:
		x = s[n - 1]
	else:
		x = s[a - 1]
	if b == 0:
		y = t[m - 1]
	else:
		y = t[b - 1]
	print(x + y)


z = list(map(int, input().split()))
a = list(map(str, input().split()))
b = list(map(str, input().split()))
n = int(input())
test = []
for i in range(n):
	j = int(input())
	test.append(j)
for i in range(n):
	first = second = 0
	if z[0] % test[i] == 0:
		first = test[i] - 1
	if z[1] % test[i] == 0:
		second = test[i] - 1
	if z[0] % test[i] != 0 or z[1] % test[i] != 0:
		first = test[i] % z[0] - 1
		second = test[i] % z[1] - 1
	print(a[first] + b[second])


(n, m) = map(int, input().split())
s = input().split()
t = input().split()
q = int(input())
for _ in range(q):
	num = int(input())
	print(s[(num - 1 + n) % n] + t[(num - 1 + m) % m])


(n, m) = map(int, input().strip().split())
arr1 = input().strip().split()
arr2 = input().strip().split()
q = int(input())
for _ in range(q):
	y = int(input())
	print(arr1[y % n - 1] + arr2[y % m - 1])


(n, m) = map(int, input().split())
a = list(map(str, input().split()))
b = list(map(str, input().split()))
for _ in [0] * int(input()):
	k = int(input())
	print(f'{a[(k - 1) % n]}{b[(k - 1) % m]}')


(a, b) = map(int, input().split())
c = input().split()
d = input().split()
e = int(input())
for x in range(e):
	f = int(input())
	print(c[f % a - 1] + d[f % b - 1])


data = input().split()
(n, m) = (int(data[0]), int(data[1]))
s = input().split()
t = input().split()
q = int(input())
for i in range(0, q):
	x = int(input())
	pp = x % n
	yy = x % m
	if pp == 0:
		pp = n
	if yy == 0:
		yy = m
	print(s[pp - 1] + t[yy - 1])


(n, m) = [int(i) for i in input().split()]
a = input().split()
b = input().split()
for i in range(int(input())):
	q = int(input())
	print(''.join([a[(q - 1) % n], b[(q - 1) % m]]))


(n, m) = map(int, input().split())
s1 = list(map(str, input().split()))
s2 = list(map(str, input().split()))
for _ in range(int(input())):
	year = int(input())
	res = s1[year % n - 1] + s2[year % m - 1]
	print(res)


(n, m) = list(map(int, input().strip().split()))
a = input().split()
b = input().split()
t = int(input())
for i in range(t):
	c = int(input())
	print(a[(c - 1) % n] + b[(c - 1) % m])


def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)
n = input()
s = input().split()
t = input().split()
n = int(input())
for i in range(n):
	x = int(input())
	print(s[(x - 1) % len(s)] + t[(x - 1) % len(t)])


(k1, k2) = input().split()
k1 = int(k1)
k2 = int(k2)
mas1 = [str(a) for a in input().split()]
mas2 = [str(a) for a in input().split()]
n = int(input())
mas3 = []
for i in range(n):
	ch = int(input())
	mas3.append(ch)
i = 0
while i < n:
	if mas3[i] <= k1:
		print(mas1[mas3[i] - 1], end='')
	if mas3[i] > k1:
		nom = mas3[i] % k1
		if nom == 0:
			nom = k1
		print(mas1[nom - 1], end='')
	if mas3[i] <= k2:
		print(mas2[mas3[i] - 1])
	if mas3[i] > k2:
		nom = mas3[i] % k2
		if nom == 0:
			nom = k2
		print(mas2[nom - 1])
	i += 1


(n, m) = map(int, input().split(' '))
words = input()
s = words.split(' ')
words1 = input()
t = words1.split(' ')
q = int(input())
y = [None] * q
for i in range(q):
	y[i] = int(input())
for i in range(q):
	a = y[i] % n
	b = y[i] % m
	print(s[a - 1] + t[b - 1])


nm = input().split(' ')
nm = [int(i) for i in nm]
Liste1 = input().split(' ')
Liste2 = input().split(' ')
testzahl = int(input())
querys = []
for i in range(testzahl):
	querys.append(int(input()))

def fun(x):
	return Liste1[x % nm[0] - 1] + Liste2[x % nm[1] - 1]
for i in querys:
	print(fun(i))


(N, M) = list(map(int, input().split()))
S = input().split()
T = input().split()
for _ in range(int(input())):
	q = int(input())
	print(S[(q - 1) % N] + T[(q - 1) % M])


def solve():
	(n, m) = [int(s) for s in input().split()]
	s = input().split()
	t = input().split()
	q = int(input())
	for i in range(q):
		x = int(input()) - 1
		print(s[x % n] + t[x % m])
solve()


(n, k) = input().split(' ')
(n, k) = (int(n), int(k))
strings1 = input().split(' ')
strings2 = input().split(' ')
q = int(input())
for _ in range(q):
	year = int(input())
	(s1, s2) = (year % n - 1, year % k - 1)
	if s1 == -1:
		s1 = n - 1
	if s2 == -1:
		s2 = k - 1
	print(strings1[s1] + strings2[s2])


(n, m) = map(int, input().split())
l1 = list(input().split())
l2 = list(input().split())
n1 = int(input())
for i in range(n1):
	x = int(input())
	v1 = x % n
	v2 = x % m
	print(l1[v1 - 1] + l2[v2 - 1])


def main():
	(n, m) = map(int, input().split())
	s = list(map(str, input().split()))
	t = list(map(str, input().split()))
	q = int(input())
	for i in range(q):
		y = int(input())
		sy = s[y % n - 1]
		ty = t[y % m - 1]
		print(sy + ty)
main()


from pprint import pprint
import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
datn = input().split()
datm = input().split()
q = int(input())
for _ in range(q):
	a = int(input())
	a -= 1
	print('{0}{1}'.format(datn[a % n], datm[a % m]))


(n, m) = map(int, input().split())
nn = input().split()
mm = input().split()
for _ in range(int(input())):
	q = int(input()) - 1
	print(nn[q % n] + mm[q % m])


(n, m) = map(int, input().split(' '))
s = input().split(' ')
t = input().split(' ')
times = int(input())
for _ in range(times):
	year = int(input()) - 1
	print(''.join((s[year % n], t[year % m])))


(n, m) = map(int, input().split())
l = input().split()
arr = input().split()
for _ in range(int(input())):
	x = int(input())
	y = x % n - 1
	if y == -1:
		y = n - 1
	z = x % m - 1
	if z == -1:
		z = m - 1
	print(l[y] + arr[z])


(n, m) = map(int, input().split())
a = input().split()
b = input().split()
t = int(input())
if len(a) < len(b):
	l = len(a)
	k = len(b)
	for i in range(t):
		x = int(input())
		if x < l:
			print(a[x - 1] + b[x - 1])
		elif x > l and x < k:
			y = x % l
			print(a[y - 1] + b[x - 1])
		else:
			y = x % l
			z = x % k
			print(a[y - 1] + b[z - 1])
else:
	l = len(a)
	k = len(b)
	for i in range(t):
		x = int(input())
		if x < k:
			print(a[x - 1] + b[x - 1])
		elif x > k and x < l:
			y = x % k
			print(a[x - 1] + b[y - 1])
		else:
			y = x % l
			z = x % k
			print(a[y - 1] + b[z - 1])


def year_name(number):
	name = ''
	name = s[(number - 1) % n] + t[(number - 1) % m]
	print(name)
(n, m) = map(int, input().split())
x = 0
least = 0
if n > m:
	x = n
	least = m
else:
	least = n
	x = m
s = list(map(str, input().split()))
t = list(map(str, input().split()))
queries = int(input())
for q in range(queries):
	y = int(input())
	year_name(y)


(n, m) = map(int, input().split())
A = input().split()
B = input().split()
q = int(input())
ans = []
for i in range(q):
	year = int(input())
	x = year % n - 1
	y = year % m - 1
	ans.append(A[x] + B[y])
for e in ans:
	print(e)


(n, m) = map(int, input().split())
S = input().split()
T = input().split()
for i in range(int(input())):
	y = int(input())
	print(S[(y - 1) % len(S)] + T[(y - 1) % len(T)])


(n, m) = map(int, input().split())
x = input()
s = x.split()
y = input()
t = y.split()
j = 0
x = int(input())
for i in range(x):
	z = int(input())
	a = s[z % n - 1]
	b = t[z % m - 1]
	print(a + b)


def solve(s, t, y):
	(n, m) = (len(s), len(t))
	return s[(y - 1) % n] + t[(y - 1) % m]
res = []
(n, m) = map(int, input().strip().split())
s = input().strip().split()
t = input().strip().split()
q = int(input().strip())
for _ in range(q):
	y = int(input().strip())
	res.append(solve(s, t, y))
for r in res:
	print(r)


x = input()
(n, m) = x.split(' ')
n = int(n)
m = int(m)
s = input()
s = s.split(' ')
t = input()
t = t.split(' ')
k = int(input())
for i in range(k):
	year = int(input())
	print(s[(year - 1) % n], end='')
	print(t[(year - 1) % m])


(x, y) = map(int, input().split())
S = input().split()
T = input().split()
N = int(input())
listQ = []
while True:
	try:
		listQ.append(input().split())
	except:
		break
Q = []
for p in range(N):
	Q.append(int(listQ[p][0]))
for i in Q:
	s = S[(i - 1) % x]
	t = T[(i - 1) % y]
	print(s + t)


(n, m) = map(int, input().split())
s = input().split()
t = input().split()
q = int(input())
for i in range(0, q):
	y = int(input())
	if y % n == 0:
		s1 = s[n - 1]
	else:
		s1 = s[y % n - 1]
	if y % m == 0:
		s2 = t[m - 1]
	else:
		s2 = t[y % m - 1]
	print(s1 + s2)


(n, m) = [int(x) for x in input().split()]
nar = [x for x in input().split()]
mar = [x for x in input().split()]
q = int(input())
for i in range(q):
	y = int(input())
	if y % n == 0:
		s = nar[n - 1]
	else:
		s = nar[y % n - 1]
	if y % m == 0:
		s += mar[m - 1]
	else:
		s += mar[y % m - 1]
	print(s)


(n, m) = map(int, input().split())
a = list(map(str, input().split()))
b = list(map(str, input().split()))
q = int(input())
for i in range(q):
	y = int(input())
	y = y - 1
	a1 = y % n
	b1 = y % m
	print(a[a1] + b[b1])


(n, m) = map(int, input().split())
arr1 = list(map(str, input().split()))
arr2 = list(map(str, input().split()))
q = int(input())
for l in range(q):
	y = int(input())
	print(arr1[y % n - 1] + arr2[y % m - 1])


(n, m) = [int(i) for i in input().split()]
a = [i for i in input().split()]
b = [i for i in input().split()]
t = int(input())
while t > 0:
	k = int(input())
	p = k % n
	q = k % m
	if p == 0:
		p = n
	if q == 0:
		q = m
	print(a[p - 1] + b[q - 1])
	t -= 1


(a, b) = map(int, input().split())
n = input().split()
m = input().split()
x = int(input())
for i in range(x):
	c = int(input()) - 1
	print(n[c % a] + m[c % b])


(a, b) = map(int, input().split())
l1 = input().split()
l2 = input().split()
for i in range(int(input())):
	m = int(input())
	if m % a == 0:
		print(l1[-1], end='')
	else:
		print(l1[m % a - 1], end='')
	if m % b == 0:
		print(l2[-1])
	else:
		print(l2[m % b - 1])


(n, m) = [int(x) for x in input().split(' ')]
s = input().split(' ')
t = input().split(' ')
q = int(input())
for case in range(q):
	y = int(input())
	print(s[(y - 1) % n] + t[(y - 1) % m])


(n, m) = map(int, input().split())
A = input().split()
B = input().split()
for i in range(int(input())):
	k = int(input())
	print(A[(k - 1) % n] + B[(k - 1) % m])


(n, m) = map(int, input().split())
s = input().split()
t = input().split()
q = int(input())
r = []
for i in range(q):
	r.append(int(input()))
for year in r:
	print(s[(year - 1) % n] + t[(year - 1) % m])


s = input().split()
list1 = list(input().split())
list2 = list(input().split())
q = int(input())
while q > 0:
	num = int(input())
	print(list1[num % int(s[0]) - 1], list2[num % int(s[1]) - 1], sep='')
	q -= 1


x = input().split()
n = int(x[0])
m = int(x[1])
ns = input().split()
ms = input().split()
q = int(input())
for i in range(q):
	t = int(input())
	print(ns[t % n - 1] + ms[t % m - 1])


(n, m) = map(int, input().split())
s = list(map(str, input().split()))
t = list(map(str, input().split()))
q = int(input())
for _ in range(q):
	x = int(input())
	(i, j) = (0, 0)
	i = (i + x - 1) % n
	j = (j + x - 1) % m
	a = [s[i], t[j]]
	print(''.join(map(str, a)))


(n, m) = map(int, input().split())
nsl = list(map(str, input().split()))
msl = list(map(str, input().split()))
q = int(input())
for rwer in range(q):
	k = int(input())
	print(nsl[(k - 1) % n] + msl[(k - 1) % m])


(x, y) = map(int, input().split())
word1 = input().split()
word2 = input().split()
for i in range(int(input())):
	a = int(input())
	print(word1[a % x - 1] + word2[a % y - 1])


(n, m) = map(int, input().split())
a = input()
b = input()
lis_a = a.split(' ')
lis_b = b.split(' ')
dic_a = {}
dic_b = {}
for i in range(n):
	rem = (i + 1) % n
	dic_a[rem] = lis_a[i]
for i in range(m):
	rem = (i + 1) % m
	dic_b[rem] = lis_b[i]
q = int(input())
for i in range(q):
	num = int(input())
	rem_a = num % n
	rem_b = num % m
	print(dic_a[rem_a] + dic_b[rem_b])


(n, m) = map(int, input().split())
(s, t) = eval('input().split(),' * 2)
q = int(input())
for _ in range(0, q):
	y = int(input()) - 1
	print(s[y % n] + t[y % m])


import sys

class ANewYearAndNaming:

	def solve(self):
		(n, m) = [int(_) for _ in input().split()]
		s = [item for item in input().split()]
		t = [item for item in input().split()]
		for _ in range(int(input())):
			y = int(input())
			print(s[(y - 1) % n] + t[(y - 1) % m])
solver = ANewYearAndNaming()
input = sys.stdin.readline
solver.solve()


while True:
	s = 0
	x = input('')
	l = x.split(' ')
	for i in range(len(l)):
		l[i] = int(l[i])
		if 0 < l[i] < 21:
			s += 1
	if s == len(l):
		break
while True:
	a = 0
	ch1 = input('')
	h = ch1.split(' ')
	for i in range(len(h)):
		if 0 < len(h[i]) < 11 and h[i] == h[i].lower():
			a += 1
	if a == len(h) and len(h) == l[0]:
		break
while True:
	b = 0
	ch2 = input('')
	E = ch2.split(' ')
	for i in range(len(E)):
		if 0 < len(E[i]) < 11 and E[i] == E[i].lower():
			b += 1
	if b == len(E) and len(E) == l[1]:
		break
while True:
	y = int(input(''))
	if 0 < y < 2021:
		break
m = list()
for i in range(y):
	while True:
		p = int(input(''))
		if 0 < p:
			break
	m.append(p)
for j in range(y):
	w = 0
	n = 0
	if m[j] >= l[0]:
		w = m[j] % l[0]
	else:
		w = m[j]
	if m[j] >= l[1]:
		n = m[j] % l[1]
	else:
		n = m[j]
	print(h[w - 1] + E[n - 1])


(n, m) = map(int, input().split())
arr = list(map(str, input().strip().split()))
arr2 = list(map(str, input().strip().split()))
q = int(input())
for i in range(q):
	t = int(input())
	k = 0
	k1 = 0
	if t % n == 0 and t / n == 1:
		k = n
	else:
		k = t % n
	if t % m == 0 and t / m == 1:
		k1 = m
	else:
		k1 = t % m
	fin = arr[k - 1] + arr2[k1 - 1]
	print(fin)


(n, m) = map(int, input().split())
a = input()
b = input()
l1 = a.split(' ')
l2 = b.split(' ')
q = int(input())
for _ in range(q):
	x = int(input())
	y = x % n - 1
	z = x % m - 1
	print(l1[y] + l2[z])


(n, m) = map(int, input().split())
ss = [i for i in input().split()]
tt = [i for i in input().split()]
q = int(input())
for _ in range(0, q):
	y = int(input())
	a = ss[(y - 1) % n] + tt[(y - 1) % m]
	print(a)


(a, b) = map(int, input().split())
s1 = input().split()
s2 = input().split()
n = int(input())
for i in range(n):
	x = int(input())
	print(s1[(x - 1) % len(s1)] + s2[(x - 1) % len(s2)])


(n, m) = map(int, input().split(' '))
l1 = input().split(' ')
l2 = input().split(' ')
q = int(input())
for i in range(q):
	s = int(input())
	print(l1[(s - 1) % n] + l2[(s - 1) % m])


sol = []
(n, m) = map(int, input().strip().split(' '))

def solve(x, l, k):
	p = ''
	y = (x - 1) % len(l)
	z = (x - 1) % len(k)
	p = l[y] + k[z]
	return p
l = input().split(' ')
k = input().split(' ')
t = int(input())
for i in range(t):
	x = int(input())
	res = solve(x, l, k)
	sol.append(res)
for i in sol:
	print(i)


inp = input().split(' ')
n = int(inp[0])
m = int(inp[1])
s = input().split(' ')
t = input().split(' ')
q = int(input())
for i in range(q):
	y = int(input())
	if y > n:
		s_n = y - round(y / n) * n
	else:
		s_n = y
	if y > m:
		t_m = y - round(y / m) * m
	else:
		t_m = y
	if s_n <= 0:
		s_n += n
	if t_m <= 0:
		t_m += m
	print(f'{s[s_n - 1]}{t[t_m - 1]}')


(n, m) = [int(x) for x in input().split()]
s = list(input().split())
p = list(input().split())
q = int(input())
for _ in range(q):
	x = int(input())
	a = x % n
	if a == 0:
		a = n
	a -= 1
	b = x % m
	if b == 0:
		b = m
	b -= 1
	print(s[a] + p[b])


def main():
	(n, m) = list(map(int, input().split()))
	ns = list(input().split())
	ms = list(input().split())
	q = int(input())
	for _ in range(q):
		k = int(input())
		k -= 1
		k1 = k % n
		k2 = k % m
		print(ns[k1] + ms[k2])
	return

def __starting_point():
	main()
__starting_point()


(n, m) = map(int, input().split())
a = input().split()
a.insert(0, a[-1])
del a[-1]
b = input().split()
b.insert(0, b[-1])
del b[-1]
for _ in [0] * int(input()):
	c = int(input())
	print(a[c % n] + b[c % m])


n = [int(i) for i in input().split(' ')]
a = input().split(' ')
b = input().split(' ')
t = int(input())
for i in range(t):
	year = int(input())
	print(a[year % n[0] - 1] + b[year % n[1] - 1])


def answer():
	nm = [int(x) for x in input().split()]
	n = nm[0]
	m = nm[1]
	s1 = input().split()
	s2 = input().split()
	q = int(input())
	while q:
		targ = int(input())
		print(s1[targ % n - 1] + s2[targ % m - 1])
		q -= 1
answer()


def year(n, s, t):
	h1 = n % len(s) - 1
	h2 = n % len(t) - 1
	return s[h1] + t[h2]
(n, m) = map(int, input().split())
s = [str(i) for i in input().split()]
t = [str(i) for i in input().split()]
a = []
q = int(input())
for i in range(q):
	n = int(input())
	a.append(year(n, s, t))
for i in a:
	print(i)


(n, m) = map(int, input().split())
a = input().split()
b = input().split()
q = int(input())
for i in range(q):
	p = int(input())
	pa = p % n - 1
	pb = p % m - 1
	print(a[pa] + b[pb])


nm = input().split()
sn = input().split()
tm = input().split()
t = int(input())
for i in range(t):
	year = int(input())
	first = (year - 1) % int(nm[0])
	second = (year - 1) % int(nm[1])
	print(sn[first] + tm[second])


line1 = input()
n = input()
m = input()
question = input()
quest = []
n1 = 0
n2 = 0
w1 = ''
w2 = ''
year = line1.split()
s = n.split()
t = m.split()
for i in range(0, int(question)):
	x = int(input())
	quest.append(x)
for i in range(0, int(question)):
	n1 = quest[i] % int(year[0])
	n2 = quest[i] % int(year[1])
	if n1 == 0:
		w1 = s[int(year[0]) - 1]
	else:
		w1 = s[n1 - 1]
	if n2 == 0:
		w2 = t[int(year[1]) - 1]
	else:
		w2 = t[n2 - 1]
	print(w1 + w2)


f = lambda : input().split()
(a, b) = map(int, f())
(c, d) = (f(), f())
for _ in [1] * int(input()):
	n = int(input())
	print(c[n % a - 1] + d[n % b - 1])


(n, m) = map(int, input().split())
nl = input().split()
ml = input().split()
q = int(input())
for _ in range(q):
	ans = ''
	x = int(input())
	if x % n > 0:
		ans += nl[x % n - 1]
	else:
		ans += nl[n - 1]
	if x % m > 0:
		ans += ml[x % m - 1]
	else:
		ans += ml[m - 1]
	print(ans)


(n, m) = list(map(int, input().split()))
s = input().split()
t = input().split()
q = int(input())
results = list()
for x in range(q):
	y = int(input())
	s_index = y - len(s) * (y // len(s)) - 1
	t_index = y - len(t) * (y // len(t)) - 1
	res = f'{s[s_index]}{t[t_index]}'
	results.append(res)
for result in results:
	print(result)


from sys import stdin, stdout

def main():
	(n1, n2) = tuple([int(x) for x in stdin.readline().split()])
	arr1 = [x for x in stdin.readline().split()]
	arr2 = [x for x in stdin.readline().split()]
	q = int(stdin.readline())
	res = []
	for i in range(0, q):
		year = int(stdin.readline())
		part_1 = arr1[(year - 1) % n1]
		part_2 = arr2[(year - 1) % n2]
		res.append(part_1 + part_2)
	stdout.write('\n'.join((str(x) for x in res)))
main()


(n, m) = [int(x) for x in input().strip().split()]
s1 = input().strip().split()
s2 = input().strip().split()
t = int(input())
a = n
b = m
while a != b and a != 0 and (b != 0):
	if a > b:
		a = a - b
	else:
		b = b - a
nok = n * m // max(a, b)
otv = []
a = 0
b = 0
for i in range(nok):
	if a == n:
		a = 0
	if b == m:
		b = 0
	otv.append(s1[a] + s2[b])
	a += 1
	b += 1
for i in range(t):
	h = int(input())
	print(otv[(h - 1) % nok])


(n, s) = map(int, input().split())
arr = list(input().split())
arr2 = list(input().split())
for _ in range(int(input())):
	k = []
	p = int(input())
	k.append(arr[p % n - 1])
	k.append(arr2[p % s - 1])
	j = ''.join([str(i) for i in k])
	print(j)


(sl, tl) = map(int, input().split(' '))
s = input().split(' ')
t = input().split(' ')
q = int(input())
for i in range(q):
	qn = int(input())
	print(s[(qn - 1) % sl] + t[(qn - 1) % tl])


(n, m) = map(int, input().split())
s = input().split()
t = input().split()
q = int(input())
for _ in range(q):
	y = int(input())
	y -= 1
	ps = y % n
	pt = y % m
	print(s[ps] + t[pt])


(n, m) = input().split()
n = int(n)
m = int(m)
s1 = input().split()
s2 = input().split()
q = int(input())
f = []
for i in range(q):
	f.append(int(input()))
na = []
f1 = 0
f2 = 0
c = 0
while c < n * m:
	c += 1
	na.append(s1[f1] + s2[f2])
	f1 += 1
	f1 %= n
	f2 += 1
	f2 %= m
for i in range(q):
	cu = f[i] - 1
	cu %= n * m
	print(na[cu])


(n, m) = list(map(int, input().split()))
S = list(map(str, input().split()))
T = list(map(str, input().split()))
q = int(input())
for i in range(q):
	hehe = int(input())
	s = hehe % n
	t = hehe % m
	if s == 0:
		s = n - 1
	else:
		s -= 1
	if t == 0:
		t = m - 1
	else:
		t -= 1
	print(S[s] + T[t])


(a, b) = map(int, input().split())
x = list(map(str, input().split()))
y = list(map(str, input().split()))
n = int(input())
for i in range(n):
	m = int(input())
	i = m % a
	j = m % b
	print(x[i - 1] + y[j - 1])


(n, m) = [int(x) for x in input().split()]
nst = [x for x in input().split()]
mst = [x for x in input().split()]
q = int(input())
for i in range(q):
	y = int(input())
	print(nst[(y - 1) % n] + mst[(y - 1) % m])


(n, m) = map(int, input().split())
tmp = n * m
a = input().split()
b = input().split()
q = int(input())
for i in range(q):
	x = int(input())
	x %= tmp
	print(a[(x + n - 1) % n] + b[(x + m - 1) % m])


import sys
readline = sys.stdin.readline
(N, M) = map(int, readline().split())
S = [list(map(ord, s)) for s in readline().strip().split()]
T = [list(map(ord, s)) for s in readline().strip().split()]
Q = int(readline())
Ans = [None] * Q
for qu in range(Q):
	j = int(readline())
	j -= 1
	k = S[j % N] + T[j % M]
	Ans[qu] = k
print('\n'.join((''.join(map(chr, a)) for a in Ans)))


import sys
Input = sys.stdin.readline
(n, m) = map(int, Input().split())
(a, b) = (Input().split(), Input().split())
for i in range(int(Input())):
	In = int(Input())
	tmp = a[In % n - 1]
	tmp2 = b[In % m - 1]
	print(tmp + tmp2)


(n, m) = map(int, input().split())
l1 = list(input().split())
l2 = list(input().split())
t = int(input())
for _ in range(t):
	n1 = int(input())
	s1 = ''
	s2 = ''
	d1 = 0
	d2 = 0
	d1 = n1 % n
	d2 = n1 % m
	if d1 == 0:
		s1 += l1[len(l1) - 1]
	else:
		s1 += l1[d1 - 1]
	if d2 == 0:
		s2 += l2[len(l2) - 1]
	else:
		s2 += l2[d2 - 1]
	print(s1 + s2)


(n, m) = map(int, input().split())
str1 = list(input().split())
str2 = list(input().split())
for i in range(int(input())):
	year = int(input())
	year1 = year
	if year > max(n, m):
		year %= max(n, m)
	if year1 > min(n, m):
		year1 %= min(n, m)
	if m > n:
		print(str1[year1 - 1] + str2[year - 1])
	elif n >= m:
		print(str1[year - 1] + str2[year1 - 1])


def input_func():
	(pre_num, post_num) = [int(x) for x in input().split()]
	pre_list = input().split()
	post_list = input().split()
	year_num = int(input())
	year_list = []
	for i in range(year_num):
		year_list.append(int(input()))
	return (pre_list, post_list, year_list)

def find_part_name(list, year):
	if year <= len(list):
		part_name = list[year - 1]
	elif year % len(list) == 0:
		part_name = list[len(list) - 1]
	else:
		part_name = list[year % len(list) - 1]
	return part_name

def find_year_name(pre_list, post_list, year):
	pre_name = find_part_name(pre_list, year)
	post_name = find_part_name(post_list, year)
	return pre_name + post_name

def print_year_name(year_name):
	print(year_name)
(pre_list, post_list, year_list) = input_func()
for year in year_list:
	year_name = find_year_name(pre_list, post_list, year)
	print_year_name(year_name)


st = input().split(' ')
n = int(st[0])
m = int(st[1])
n1 = input().split(' ')
n2 = input().split(' ')
t = int(input())
for itt in range(t):
	y = int(input())
	y = y - 1
	f = y % n
	l = y % m
	print(n1[f] + n2[l])


(n, m) = map(int, input().split())
ns = list(input().split())
ms = list(input().split())
Q = int(input())
for z in range(Q):
	q = int(input())
	s = ns[(q - 1) % n] + ms[(q - 1) % m]
	print(s)


def solve(y):
	return s[y % n] + t[y % m]

def main():
	global n, m, s, t
	(n, m) = list(map(int, input().split()))
	s = input().split()
	t = input().split()
	for _ in range(int(input())):
		y = int(input())
		print(solve(y - 1))
main()


(n, m) = [int(x) for x in input().split()]
s = input().strip().split()
t = input().strip().split()
q = int(input())
for _ in range(q):
	y = int(input())
	r1 = (y - 1) % n
	r2 = (y - 1) % m
	print(s[r1] + t[r2])


arr_lengths = [int(num) for num in input().split()]
arr1 = [word for word in input().split()]
arr2 = [word for word in input().split()]
num_of_entries = int(input())
for _ in range(num_of_entries):
	year = int(input())
	part1 = year % arr_lengths[0]
	part2 = year % arr_lengths[1]
	if part1 == 0:
		part1 = arr_lengths[0]
	if part2 == 0:
		part2 = arr_lengths[1]
	part1 = arr1[part1 - 1]
	part2 = arr2[part2 - 1]
	print(part1 + part2)


sk = list(map(int, input().split()))
sk1 = sk[0]
sk2 = sk[1]
s1 = input().split()
s2 = input().split()
for i in range(int(input())):
	k = int(input())
	k1 = k % sk1
	k2 = k % sk2
	print(s1[k1 - 1] + s2[k2 - 1])


(a, b) = map(int, input().split())
l1 = list(map(str, input().split()))
l2 = list(map(str, input().split()))
n = int(input())
for i in range(n):
	z = int(input())
	m1 = z % a
	m2 = z % b
	if m1 != 0:
		str1 = l1[m1 - 1]
	else:
		str1 = l1[-1]
	if m2 != 0:
		str2 = l2[m2 - 1]
	else:
		str2 = l2[-1]
	print(str1 + str2)


line1 = list(map(int, input().split()))
n = input().split()
m = input().split()
q = int(input())
queries = []
for i in range(q):
	queries.append(int(input()))
answer = []
for i in range(q):
	word1 = n[queries[i] % line1[0] - 1]
	word2 = m[queries[i] % line1[1] - 1]
	ans = word1 + word2
	answer.append(ans)
for i in range(q):
	print(answer[i])


(n, m) = map(int, input().split())
N = list(input().split())
M = list(input().split())
for _ in range(int(input())):
	year = int(input())
	a = year % n - 1
	b = year % m - 1
	print(N[a] + M[b])


(a, b) = list(map(int, input().split()))
h = list(map(str, input().split()))
h1 = list(map(str, input().split()))
k = int(input())
for i in range(k):
	p = int(input())
	t = p
	t1 = p
	if p >= a:
		t %= a
	if p >= b:
		t1 %= b
	print(h[t - 1] + h1[t1 - 1])


(a, b) = map(int, input('').split())
l = input('').split()
ll = input('').split()
c = int(input(''))
for x in range(c):
	d = int(input(''))
	s = d % b - 1
	d = d % a - 1
	if d == -1:
		d = a - 1
	if s == -1:
		s = b - 1
	print(l[d], end='')
	print(ll[s], end='')
	print()


(n, m) = [int(i) for i in input().split()]
s = input().split()
t = input().split()
for i in range(int(input())):
	print((lambda y: s[y % n - 1] + t[y % m - 1])(int(input())))


(n, m) = [int(n) for n in input().split()]
s = [] * n
t = [] * m
s = input().split()
t = input().split()
no = int(input())
ans = list()
for i in range(0, no):
	req_no = int(input())
	ans = ans + [s[(req_no - 1) % n] + t[(req_no - 1) % m]]
for i in ans:
	print(i)


import os
import sys
from io import BytesIO, IOBase

def main():
	(a, b) = map(int, input().split())
	a1 = list(input().split())
	a1 = [a1[-1]] + a1[:-1]
	a2 = list(input().split())
	a2 = [a2[-1]] + a2[:-1]
	n = int(input())
	for i in range(n):
		v = int(input())
		ans = ''
		ans += a1[v % a]
		ans += a2[v % b]
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


(n, m) = map(int, input().split())
sn = list(input().split())
sm = list(input().split())
q = int(input())
while q:
	q -= 1
	y = int(input())
	n_i = y % n
	if n_i == 0:
		n_i = n - 1
	else:
		n_i -= 1
	m_i = y % m
	if m_i == 0:
		m_i = m - 1
	else:
		m_i -= 1
	print(sn[n_i] + sm[m_i])


(n, m) = map(int, input().split())
list_n = list(map(str, input().split()))
list_m = list(map(str, input().split()))
queries = int(input())
for query in range(queries):
	q = int(input())
	print(list_n[(q - 1) % n] + list_m[(q - 1) % m])


(a, b) = map(int, input().split())
s = input().split()
p = input().split()
q = int(input())
for _ in range(q):
	e = int(input())
	print(s[(e - 1) % a], end='')
	print(p[(e - 1) % b])


(n, m) = map(int, input().split())
s1 = input().split()
s2 = input().split()
for _ in range(int(input())):
	x = int(input())
	print(str(s1[(x - 1) % n]) + str(s2[(x - 1) % m]))


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(100000000)
	threading.stack_size(40960000)
	thread = threading.Thread(target=main)
	thread.start()
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[1]

def sort2(l):
	return sorted(l, key=getKey)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def main():
	(n, m) = mi()
	s = list(msi())
	t = list(msi())
	q = ii()
	for i in range(q):
		x = ii() - 1
		print(s[x % n] + t[x % m])
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


s = list(map(int, input().split(' ')))
s_1 = input().split(' ')
s_2 = input().split(' ')
n = int(input())
lis = []
r_1 = 0
r_2 = 0
q = 0
for i in range(n):
	string = ''
	q = int(input())
	r_1 = q % s[0]
	r_2 = q % s[1]
	if r_1 == 0:
		string += s_1[s[0] - 1]
	else:
		string += s_1[r_1 - 1]
	if r_2 == 0:
		string += s_2[s[1] - 1]
	else:
		string += s_2[r_2 - 1]
	lis.append(string)
for i in lis:
	print(i)


(n, m) = list(map(int, input().split()))
a = list(input().split())
b = list(input().split())
q = int(input())
for i in range(q):
	tmp = int(input())
	s = ''
	s += a[(tmp - 1) % n]
	s += b[(tmp - 1) % m]
	print(s)


(n, m) = map(int, input().split())
a = input().split()
b = input().split()
q = int(input())
(la, lb) = (len(a), len(b))
for i in range(q):
	y = int(input()) - 1
	print(a[y % la] + b[y % lb])


(n, m) = map(int, input().split())
a = list(map(str, input().split()))
b = list(map(str, input().split()))
for _ in range(int(input())):
	yr = int(input())
	v = a[yr % n - 1] + b[yr % m - 1]
	print(v)


(n, m) = map(int, input().split())
s = input()
t = input()
s = s.split()
t = t.split()
q = int(input())
for _ in range(q):
	y = int(input())
	y = y - 1
	pts = y % n
	ptt = y % m
	print(s[pts] + t[ptt])


(n, m) = map(int, input().split())
s = input()
s = s.split(' ')
t = input()
t = t.split(' ')
q = int(input())
lista = []
while q:
	x = int(input())
	lista.append(s[(x - 1) % n] + t[(x - 1) % m])
	q -= 1
for i in lista:
	print(i)


(n, m) = map(int, input().split())
lsa = input().split()
lsb = input().split()
for tc in range(int(input())):
	i = int(input()) - 1
	print(lsa[i % n] + lsb[i % m])


(n, m) = list(map(int, input().split(' ')))
s = input()
t = input()
sa = s.split(' ')
ta = t.split(' ')
qn = int(input())
w = qn
q = []
while w:
	wq = int(input())
	q.append(wq)
	w -= 1
w = qn
i = 0
while w:
	ti = q[i] % n
	to = q[i] % m
	ti -= 1
	to -= 1
	print(f'{sa[ti]}{ta[to]}')
	w -= 1
	i += 1


(n, m) = [int(i) for i in input().split(' ')]
s = input().split(' ')
t = input().split(' ')
q = int(input())
for i in range(q):
	a = int(input())
	result = s[(a - 1) % n] + t[(a - 1) % m]
	print(result)


def main():
	(n, m) = map(int, input().split())
	s = input().split()
	t = input().split()
	q = int(input())
	for _ in range(q):
		y = int(input())
		print(s[(y - 1) % n] + t[(y - 1) % m])
main()


(n, m) = map(int, input().split())
s = input().split()
t = input().split()
q = int(input())
l = []
for _ in range(q):
	l.append(int(input()))
for e in l:
	print(s[(e - 1) % n] + t[(e - 1) % m])


(n, m) = input().split(' ')
(n, m) = (int(n), int(m))
ns = input().split(' ')
ms = input().split(' ')
T = int(input())
ans = ''
for t in range(T):
	q = int(input())
	ans += ns[q % n - 1] + ms[q % m - 1] + '\n'
print(ans)


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
S = list(input().split())
T = list(input().split())
q = int(input())
ANS = []
inds = 0
indt = 0
for i in range(n * m):
	ANS.append(S[inds] + T[indt])
	inds = (inds + 1) % n
	indt = (indt + 1) % m
for test in range(q):
	Q = int(input())
	print(ANS[(Q - 1) % (n * m)])


(n, m) = [int(i) for i in input().split()]
s = input().split()
t = input().split()
T = int(input())
results = []
for case in range(1, T + 1):
	num = int(input())
	result = ''
	result += s[(num - 1) % n]
	result += t[(num - 1) % m]
	results.append(result)
for result in results:
	print(result)


(n, m) = map(int, input().split())
string_1 = input().split()
string_2 = input().split()
q = int(input())

def name(val, s1, s2):
	l1 = len(string_1)
	l2 = len(string_2)
	print(''.join([s1[val % l1 - 1], s2[val % l2 - 1]]))
for i in range(q):
	year = int(input())
	name(year, string_1, string_2)


(k, j) = map(int, input().split(' '))
s1 = input().split(' ')
s2 = input().split(' ')
q = int(input())
for i in range(q):
	n = int(input())
	n -= 1
	sout = s1[n % k] + s2[n % j]
	print(sout)


line = input().split()
N = int(line[0])
M = int(line[1])
s = input().split()
t = input().split()
q = int(input())
for a in range(q):
	year = int(input())
	print(s[(year - 1) % N] + t[(year - 1) % M])


(n, m) = map(int, input().split())
l = list(map(str, input().split()))
p = list(map(str, input().split()))
w = int(input())
for i in range(w):
	r = int(input())
	t = r % n
	if t == 0:
		t = n
	d = r % m
	if d == 0:
		d = m
	print(l[t - 1] + p[d - 1])


(n, m) = (int(x) for x in input().strip().split())
a = input().split(' ')
b = input().split(' ')
q = int(input())
arr = []
for i in range(q):
	arr.append(int(input()))
for i in arr:
	if i > n:
		j = i % n
		if j == 0:
			j = n - 1
		else:
			j -= 1
	else:
		j = i - 1
	s = a[j]
	if i > m:
		j = i % m
		if j == 0:
			j = m - 1
		else:
			j -= 1
	else:
		j = i - 1
	s += b[j]
	print(s)


mn = list(map(int, input().split()))
(m, n) = (mn[0], mn[1])
ms = list(map(str, input().split()))
ns = list(map(str, input().split()))
q = int(input())
for i in range(q):
	a = int(input())
	f = ms[(a - 1) % len(ms)]
	l = ns[(a - 1) % len(ns)]
	print(f + l)


def yearName(A, B, year):
	i = 0
	j = 0
	counter = 1
	num = year % (len(A) * len(B))
	while counter <= num:
		if i == len(A):
			i = 0
		if j == len(B):
			j = 0
		i += 1
		j += 1
		counter += 1
	return A[i - 1] + B[j - 1]
intergers = input()
arr1 = list(map(str, input().split()))
arr2 = list(map(str, input().split()))
q = int(input())
for i in range(q):
	year = int(input())
	print(yearName(arr1, arr2, year))


(n, m) = map(int, input().split())
s = input().split()
t = input().split()
q = int(input())
for p in range(q):
	y = int(input())
	i = y % n
	if i == 0:
		i == n
	j = y % m
	if j == 0:
		j == m
	print(s[i - 1] + t[j - 1])


t = list(map(int, input().split()))
a = input()
a = a.split()
b = input()
b = b.split()
q = int(input())
for i in range(0, q):
	y = int(input())
	s = a[y % len(a) - 1] + b[y % len(b) - 1]
	print(s)


temp = [int(x) for x in input().split()]
n = temp[0]
m = temp[1]
s = input().split()
t = input().split()
q = int(input())
for i in range(q):
	y = int(input())
	print(s[y % n - 1] + t[y % m - 1])


(n, m) = [int(x) for x in input().split()]
data_n = [x for x in input().split()]
data_m = [x for x in input().split()]
for i in range(int(input())):
	a = int(input())
	print(data_n[a % n - 1], data_m[a % m - 1], sep='')


(a, b) = map(int, input().split())
(A, B) = [input().split() for i in range(2)][0:]
for i in range(int(input())):
	x = int(input())
	print(A[x % a - 1] + B[x % b - 1])


(n, m) = map(int, input().split())
ss = input().split()
ts = input().split()
q = int(input())
for _ in range(q):
	ind = int(input()) - 1
	s = ss[ind % n]
	t = ts[ind % m]
	print(s + t)


(n, m) = input().split()
(n, m) = (int(n), int(m))
s = input().split()
t = input().split()
q = int(input())
inp = []
for i in range(q):
	inp.append(int(input()))
res = []
for el in inp:
	temps = ''
	temps += s[el % n - 1]
	temps += t[el % m - 1]
	res.append(temps)
for el in res:
	print(el)


s = input()
v = list(map(int, s.split()))
n = v[0]
m = v[1]
s = input()
t1 = []
t1 = s.split()
s = input()
t2 = []
t2 = s.split()
t = int(input())
while t > 0:
	t -= 1
	k = int(input())
	r1 = k % n
	if r1 == 0:
		r1 = n
	r2 = k % m
	if r2 == 0:
		r2 = m
	act = t1[r1 - 1] + t2[r2 - 1]
	print(str(act))


(n, m) = map(int, input().split())
s = list(map(str, input().split()))
t = list(map(str, input().split()))
for _ in range(int(input())):
	i1 = int(input())
	print(s[i1 % n - 1] + t[i1 % m - 1])


def name_yr(n, m, s, t, yr):
	a = yr % n
	b = yr % m
	if a:
		f_name = s[a - 1]
	else:
		f_name = s[-1]
	if b:
		l_name = t[b - 1]
	else:
		l_name = t[-1]
	ans = f_name + l_name
	return ans
nm = input().split()
n = int(nm[0])
m = int(nm[1])
s = input().split()
t = input().split()
q = int(input())
for _ in range(q):
	yr = int(input())
	print(name_yr(n, m, s, t, yr))


(a, b) = map(int, input().split())
la = list(input().split())
lb = list(input().split())
n = int(input())
for i in range(n):
	num = int(input())
	print(la[num % a - 1] + lb[num % b - 1])


(a, b) = map(int, input().split())
x = [v for v in input().split()]
y = [v for v in input().split()]
q = int(input())
while q != 0:
	n = int(input())
	q -= 1
	c = ''
	d1 = n % len(x)
	d2 = n % len(y)
	if d1 == 0:
		c += x[len(x) - 1]
	if d1 != 0:
		c += x[d1 - 1]
	if d2 == 0:
		c += y[len(y) - 1]
	if d2 != 0:
		c += y[d2 - 1]
	print(c)


(n, m) = map(int, input().split())
s1 = input()
s2 = input()
s1 = s1.split(' ')
s2 = s2.split(' ')
q = int(input())
for _ in range(q):
	no = int(input())
	a = s1[no % n - 1]
	b = s2[no % m - 1]
	print(a + b)


(n, m) = map(int, input().split())
s1 = list(input().split())
s2 = list(input().split())
for i in range(int(input())):
	r = int(input())
	print(s1[(r - 1) % len(s1)] + s2[(r - 1) % len(s2)])


(n, m) = map(int, input().split())
s = list(input().split())
t = list(input().split())
q = int(input())
a = [0] * q
for i in range(q):
	a[i] = int(input())
for ai in a:
	print(s[(ai - 1) % len(s)] + t[(ai - 1) % len(t)])


(n, m) = map(int, input().split())
s = input().split()
t = input().split()
k = int(input())
len_s = len(s)
len_t = len(t)
for _ in range(k):
	i = int(input())
	i = i - 1
	idx_s = i % len_s
	idx_t = i % len_t
	print(s[idx_s] + t[idx_t])


a = input().split()
b = input().split()
c = input().split()
q = int(input())
for i in range(0, q):
	k = int(input())
	ind1 = k % int(a[0]) - 1
	ind2 = k % int(a[1]) - 1
	print(b[ind1] + c[ind2])


(n, m) = map(int, input().split())
l = input().split()
t = input().split()
q = int(input())
for _ in range(q):
	y = int(input())
	y -= 1
	print(l[y % n] + t[y % m])


from bisect import *
(n, m) = map(int, input().split())
nn = list(map(str, input().split()))
mm = list(map(str, input().split()))
for _ in range(int(input())):
	k = int(input())
	print(nn[(k - 1) % n] + mm[(k - 1) % m])


(a, b) = input().split()
a = int(a)
b = int(b)
x1 = input()
y1 = input()
x = x1.split()
y = y1.split()
n = int(input())
for i in range(n):
	num = int(input())
	num = int(num - 1)
	a1 = int(num % a)
	b1 = int(num % b)
	print('{}{}'.format(x[a1], y[b1]))


a = input().split(' ')
s = input().split(' ')
t = input().split(' ')
n = int(a[0])
m = int(a[1])
q = int(input())
li = []
for i in range(q):
	y = int(input())
	n1 = y % n
	if n1 == 0:
		n1 = n
	m1 = y % m
	if m1 == 0:
		m1 = m
	s1 = s[n1 - 1]
	t1 = t[m1 - 1]
	li.append(s1 + t1)
for i in range(len(li)):
	print(li[i])


arraynuminput = input()
arraystr = [int(x) for x in arraynuminput.split()]
s = []
t = []
query_arr = []
s_words = input()
s_words_split = s_words.split()
t_words = input()
t_words_split = t_words.split()
query = int(input())
for i in range(0, query):
	add = int(input())
	query_arr.append(add)
for i in range(0, query):
	year = query_arr[i]
	if year % arraystr[0] == 0 and year % arraystr[1] == 0:
		print(s_words_split[arraystr[0] - 1], end='')
		print(t_words_split[arraystr[1] - 1])
	elif year % arraystr[0] != 0 and year % arraystr[1] != 0:
		print(s_words_split[year % arraystr[0] - 1], end='')
		print(t_words_split[year % arraystr[1] - 1])
	elif year % arraystr[0] == 0 and year % arraystr[1] != 0:
		print(s_words_split[arraystr[0] - 1], end='')
		print(t_words_split[year % arraystr[1] - 1])
	elif year % arraystr[0] != 0 and year % arraystr[1] == 0:
		print(s_words_split[year % arraystr[0] - 1], end='')
		print(t_words_split[arraystr[1] - 1])


(n, m) = map(int, input().split())
s = list(map(str, input().split()))
t = list(map(str, input().split()))
s1 = len(s)
t1 = len(t)
for _ in range(int(input())):
	n = int(input())
	print(s[n % s1 - 1] + t[n % t1 - 1])


nm = input()
n = int(nm[:nm.find(' ')])
m = int(nm[nm.find(' ') + 1:])
sn = input()
sn = sn.split()
sm = input()
sm = sm.split()
q = int(input())
for i in range(q):
	y = int(input())
	pos1 = y
	pos1 = y % n
	pos2 = y
	pos2 = y % m
	print(sn[pos1 - 1] + sm[pos2 - 1])


(n, m) = list(map(int, input().split()))
l1 = list(map(str, input().split()))
l2 = list(map(str, input().split()))
t = int(input())
for i in range(t):
	j = int(input())
	print(l1[j % n - 1] + l2[j % m - 1])


from sys import stdin

def input():
	return stdin.readline()[:-1]

def intput():
	return int(input())

def sinput():
	return input().split()

def intsput():
	return map(int, sinput())
debugging = False

def dprint(*args):
	if debugging:
		print(*args)
	else:
		pass
(n, m) = intsput()
s = input().split()
t = input().split()
q = intput()
for _ in range(q):
	y = intput()
	print(s[(y - 1) % len(s)] + t[(y - 1) % len(t)])


import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue

class Scanner:

	@staticmethod
	def int():
		return int(sys.stdin.readline().rstrip())

	@staticmethod
	def string():
		return sys.stdin.readline().rstrip()

	@staticmethod
	def map_int():
		return [int(x) for x in Scanner.string().split()]

	@staticmethod
	def string_list(n):
		return [input() for i in range(n)]

	@staticmethod
	def int_list_list(n):
		return [Scanner.map_int() for i in range(n)]

	@staticmethod
	def int_cols_list(n):
		return [int(input()) for i in range(n)]

class Math:

	@staticmethod
	def gcd(a, b):
		if b == 0:
			return a
		return Math.gcd(b, a % b)

	@staticmethod
	def lcm(a, b):
		return a * b // Math.gcd(a, b)

	@staticmethod
	def divisor(n):
		res = []
		i = 1
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0:
				res.append(i)
				if i != n // i:
					res.append(n // i)
		return res

	@staticmethod
	def round_up(a, b):
		return -(-a // b)

	@staticmethod
	def is_prime(n):
		if n < 2:
			return False
		if n == 2:
			return True
		if n % 2 == 0:
			return False
		d = int(n ** 0.5) + 1
		for i in range(3, d + 1, 2):
			if n % i == 0:
				return False
		return True

class PriorityQueue:

	def __init__(self, l=[]):
		self.q = l
		heapq.heapify(self.q)
		return

	def push(self, n):
		heapq.heappush(self.q, n)
		return

	def pop(self):
		return heapq.heappop(self.q)
MOD = int(1000000000.0) + 7
INF = int(1000000000000000.0)

def main():
	(n, m) = Scanner.map_int()
	S = Scanner.string().split(sep=' ')
	T = Scanner.string().split(sep=' ')
	Q = Scanner.int()
	for _ in range(Q):
		t = Scanner.int()
		t -= 1
		print(S[t % n] + T[t % m])
main()


nm = input().split()
(n, m) = (int(nm[0]), int(nm[1]))
si = input().split()
ti = input().split()
q = int(input())
while q > 0:
	y = int(input())
	y -= 1
	print(si[y % n] + ti[y % m])
	q -= 1


from math import gcd
(n, m) = map(int, input().split(' '))
s = input().split(' ')
t = input().split(' ')
times = int(input())
minimo = min(n, m)
maximo = max(n, m)
mcd = gcd(n, m)
tamano = int(minimo / mcd * maximo)
s_mult = int(n * (m / mcd))
t_mult = int(m * (n / mcd))
names = list(zip(s * s_mult, t * t_mult))
for _ in range(times):
	year = int(input()) % tamano - 1
	print(''.join(names[year]))


(n, m) = map(int, input().split())
s1 = list(input().split())
s2 = list(input().split())
q = int(input())
for i in range(q):
	year = int(input())
	k1 = (year - 1) % n
	k2 = (year - 1) % m
	print(s1[k1] + s2[k2])


(n, m) = map(int, input().split())
n_strings = tuple(input().split())
m_strings = tuple(input().split())
for _ in range(int(input())):
	x = int(input())
	print(n_strings[x % n - 1] + m_strings[x % m - 1])


import sys
import math
counter = -1
count = 0
for lin in sys.stdin:
	line = lin.rstrip()
	counter += 1
	if counter == 0:
		(c1, c2) = [int(h) for h in line.split()]
	elif counter == 1:
		l1 = line.split()
	elif counter == 2:
		l2 = line.split()
	elif counter == 3:
		count = int(line)
	elif counter <= 3 + count:
		s1 = int(line) % c1 - 1
		s2 = int(line) % c2 - 1
		if s1 == -1:
			s1 = c1 - 1
		if s2 == -1:
			s2 = c2 - 1
		print(l1[s1] + l2[s2])
	else:
		break


def main():
	tailles = input().split(' ')
	n = int(tailles[0])
	m = int(tailles[1])
	seq1 = input().split(' ')
	seq2 = input().split(' ')
	tabseq1 = [0] * n
	for k in range(n):
		tabseq1[k] = seq1[k]
	tabseq2 = [0] * m
	for k in range(m):
		tabseq2[k] = seq2[k]
	q = int(input())
	for k in range(q):
		annee = int(input())
		r1 = (annee - 1) % n
		r2 = (annee - 1) % m
		print(tabseq1[r1] + tabseq2[r2])
main()


s = input()
arr1 = [x for x in input().split()]
arr2 = [x for x in input().split()]
for y in range(int(input())):
	a = int(input())
	print(arr1[a % len(arr1) - 1] + arr2[a % len(arr2) - 1])


(a, b) = map(int, input().split())
arr = list(map(str, input().split()))
brr = list(map(str, input().split()))
q = int(input())
for i in range(q):
	u = int(input())
	if u % a == 0:
		ua = a - 1
	else:
		ua = u % a - 1
	if u % b == 0:
		ub = b - 1
	else:
		ub = u % b - 1
	print(arr[ua], brr[ub], sep='')


import sys

def main():
	(n, m) = get_ints()
	s = list(input().split())
	t = list(input().split())
	for tc in range(int(input())):
		y = int(input())
		y -= 1
		print(s[y % n] + t[y % m])
get_array = lambda : list(map(int, sys.stdin.readline().split()))
get_ints = lambda : map(int, sys.stdin.readline().split())
input = lambda : sys.stdin.readline().strip()
main()


(n, m) = map(int, input().split())
S = [s for s in input().split()]
T = [t for t in input().split()]
q = int(input())
Q = [int(input()) for _ in range(q)]
names = []
i = j = 0
for _ in range(n * m):
	names.append(S[i] + T[j])
	i = (i + 1) % n
	j = (j + 1) % m
for query in Q:
	print(names[(query - 1) % (n * m)])


(n, m) = map(int, input().split())
l = list(map(str, input().split()))
l1 = list(map(str, input().split()))
t = int(input())
for i in range(t):
	e = int(input())
	print(l[e % n - 1], end='')
	print(l1[e % m - 1])


nums = input()
(n, m) = str(nums).split(' ')
n = int(n)
m = int(m)
s = str(input()).split(' ')
t = str(input()).split(' ')
q = int(input())
for i in range(q):
	curr = int(input())
	print(s[(curr - 1) % n] + t[(curr - 1) % m])


(n, m) = map(int, input().split())
s = list(input().split())
t = list(input().split())
q = int(input())
for i in range(q):
	yr = int(input())
	if yr % n == 0:
		f = s[n - 1]
	else:
		f = s[yr % n - 1]
	if yr % m == 0:
		g = t[m - 1]
	else:
		g = t[yr % m - 1]
	print(f + g)


(n, k) = map(int, input().split())
l1 = list(map(str, input().split()))
l2 = list(map(str, input().split()))
q = int(input())
while q > 0:
	x = int(input())
	ans = l1[x % len(l1) - 1] + l2[x % len(l2) - 1]
	print(ans)
	q -= 1


(n, m) = map(int, input().split())
s = input().split()
t = input().split()
q = int(input())
for el in range(q):
	y = int(input())
	sn = y % n - 1
	tm = y % m - 1
	print(s[sn] + t[tm])


(n, m) = map(int, input().split())
n_list = input().split()
m_list = input().split()
q = int(input())
for i in range(q):
	year = int(input())
	ans = n_list[year % len(n_list) - 1] + m_list[year % len(m_list) - 1]
	print(ans)


(n, m) = map(int, input().split())
s = input().split()
t = input().split()
for i in range(int(input())):
	y = int(input())
	a = y % len(s)
	b = y % len(t)
	if a == 0:
		a = len(s)
	if b == 0:
		b = len(t)
	print(s[a - 1] + t[b - 1])


nm = input().split()
n = int(nm[0])
m = int(nm[1])
nList = input().split()
mList = input().split()
q = int(input())
for x in range(q):
	y = int(input())
	ny = y % n
	my = y % m
	print(nList[ny - 1] + mList[my - 1])


listy = list(map(int, input().split()))
prod = listy[0] * listy[1]
lista = input().split()
listb = input().split()
n = int(input())
for i in range(n):
	year = int(input())
	k = year % prod
	l = k % listy[0]
	m = k % listy[1]
	answer = lista[l - 1] + listb[m - 1]
	print(answer)


(n, m) = input().split()
n = int(n)
m = int(m)
s1 = input().split()
s2 = input().split()
q = input()
queries = []
for i in range(int(q)):
	queries.append(int(input()))
for i in range(int(q)):
	x = queries[i] % n
	y = queries[i] % m
	print(s1[x - 1] + s2[y - 1])


import string
(n, m) = map(int, input().split())
x = list(input().split())
y = list(input().split())
t = int(input())
for i in range(0, t):
	q = int(input())
	i = q % n
	j = q % m
	s = x[i - 1] + y[j - 1]
	print(s)


from sys import stdin, stdout
import sys
from bisect import bisect_left, bisect_right
import gc
gc.disable()
(n, m) = list(map(int, stdin.readline().split()))
first = list(stdin.readline().split())
second = list(stdin.readline().split())
q = int(stdin.readline().strip())
for _ in range(q):
	year = int(stdin.readline().strip())
	f = (year - 1) % n
	s = (year - 1) % m
	print(first[f] + second[s])


(n, m) = map(int, input().split())
ni = input().split()
mi = input().split()
for _ in range(int(input())):
	k = int(input())
	print(ni[k % n - 1] + mi[k % m - 1])


(n, m) = input().split()
yo1 = input().split()
yo2 = input().split()
q = int(input())
for i in range(q):
	x = int(input())
	ans = yo1[x % int(n) - 1] + yo2[x % int(m) - 1]
	print(ans)


(n, m) = map(int, input().split())
S = input().split()
T = input().split()
for _ in range(int(input())):
	a = int(input())
	print(S[(a - 1) % n] + T[(a - 1) % m])


(m, n) = map(int, input().split())
s1 = list(map(str, input().split()))
s2 = list(map(str, input().split()))
for i in range(int(input())):
	x = int(input())
	print(s1[x % m - 1] + s2[x % n - 1])


(n, m) = input().split()
n = int(n)
m = int(m)
a = [a for a in input().split()]
b = [b for b in input().split()]
output = []
q = int(input())
for i in range(q):
	num1 = num2 = int(input())
	num1 %= n
	if num1 == 0:
		num1 = n
	astring = a[num1 - 1]
	num2 %= m
	if num2 == 0:
		num2 = m
	bstring = b[num2 - 1]
	output.append(astring + bstring)
for c in output:
	print(c)


(n, m) = list(map(int, input().split(' ')))
s = input().split(' ')
t = input().split(' ')

def f(n, m, s, t, y):
	y -= 1
	return s[y % n] + t[y % m]
res = []
for q in range(int(input())):
	y = int(input())
	res.append(f(n, m, s, t, y))
for x in res:
	print(x)


(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
a = list(map(str, input().strip().split(' ')))
b = list(map(str, input().strip().split(' ')))
q = int(input())
for i in range(q):
	ans = ''
	u = int(input())
	ans += a[(u - 1) % n] + b[(u - 1) % m]
	print(ans)


import sys
input = sys.stdin.readline

def iin():
	return int(input())

def lin():
	return list(map(int, input().split()))

def main():
	(n, m) = lin()
	s = input().split()
	p = input().split()
	t = iin()
	while t:
		t -= 1
		y = iin() - 1
		print(s[y % n] + p[y % m])
main()


(a, b) = map(int, input().split())
l1 = list(map(str, input().split()))
l2 = list(map(str, input().split()))
for i in range(int(input())):
	n = int(input())
	c = n % a
	d = n % b
	s = ''
	if c == 0:
		c = a
	if d == 0:
		d = b
	s += l1[c - 1]
	s += l2[d - 1]
	print(s)


(n, m) = map(int, input().split())
firstnames = []
secondnames = []
firstnames = input().split()
secondnames = input().split()
q = int(input())
years = []
for i in range(q):
	years.append(int(input()))
for year in years:
	firstname = firstnames[(year - 1) % n]
	secondname = secondnames[(year - 1) % m]
	print(firstname + secondname)


def int_str():
	return map(int, input().split())
(n, m) = int_str()
n_s = input().split()
m_s = input().split()
q = int(input())
for _ in range(q):
	year = int(input()) - 1
	xn = year % n
	xm = year % m
	print(n_s[xn] + m_s[xm])


(n, m) = [int(n) for n in input().split()]
s = input().split()
t = input().split()
q = int(input())
for _ in range(q):
	idx = int(input())
	print(s[idx % n - 1] + t[idx % m - 1])


(n, m) = (int(i) for i in input().split())
l1 = [i for i in input().split()]
l2 = [i for i in input().split()]
q = int(input())
for i in range(q):
	y = int(input())
	print(l1[y % n - 1] + l2[y % m - 1])


(n, m) = map(int, input().split())
a = list(input().split())
b = list(input().split())
for _ in range(int(input())):
	y = int(input())
	ans = ''
	if y % n == 0:
		ans += a[n - 1]
	else:
		ans += a[y % n - 1]
	if y % m == 0:
		ans += b[m - 1]
	else:
		ans += b[y % m - 1]
	print(ans)


a = input().split()
b = input().split()
c = input().split()
d = int(input())
e = int(a[0])
f = int(a[1])
for i in range(d):
	g = int(input())
	h = g % e
	j = g % f
	if h == 0:
		h = e - 1
		k = b[h]
	else:
		h = h - 1
		k = b[h]
	if j == 0:
		j = f - 1
		k = k + c[j]
	else:
		j = j - 1
		k = k + c[j]
	print(k)


(n, m) = [int(i) for i in input().split()]
lst1 = input().split()
lst2 = input().split()
k = int(input())
for i in range(k):
	a = int(input())
	c = (a - 1) % n
	b = (a - 1) % m
	print(lst1[c] + lst2[b])


def names(s, t, q):
	val1 = s[(q - 1) % len(s)]
	val2 = t[(y - 1) % len(t)]
	return val1 + val2
(n, m) = list(map(int, input().rstrip().split()))
s = list(input().rstrip().split())
t = list(input().rstrip().split())
q = int(input())
for i in range(q):
	y = int(input())
	print(names(s, t, y))


while True:
	try:

		def solve(n, m, s, t, q):
			ts = ''
			for i in range(q):
				v = int(input())
				if v <= n:
					ts = s[v - 1]
				elif v % n != 0:
					ts = s[v % n - 1]
				elif v % n == 0:
					ts = s[n - 1]
				if v <= m:
					ts = ts + t[v - 1]
				elif v % m != 0:
					ts += t[v % m - 1]
				elif v % m == 0:
					ts += t[m - 1]
				print(ts)
				ts = ''
		if __name__ == '__main__':
			(n, m) = map(int, input().split())
			s = list(map(str, input().split()))
			t = list(map(str, input().split()))
			q = int(input())
			solve(n, m, s, t, q)
	except EOFError:
		break


(n, m) = [*map(int, input().split())]
s = input().split()
t = input().split()
for i in range(int(input())):
	y = int(input()) - 1
	print(f'{s[y % n]}{t[y % m]}')


def calculate_name(n, m, s, t, year):
	return s[year % n - 1] + t[year % m - 1]

def pre():
	(n, m) = list(map(int, input().split(' ')))
	s = input().split(' ')
	t = input().split(' ')
	return (n, m, s, t)
import collections
(n, m, s, t) = pre()
for x in range(int(input())):
	print(calculate_name(n, m, s, t, int(input())))


(n, m) = map(int, input().split())
s1 = input().split()
s2 = input().split()
s1.insert(0, s1[-1])
s2.insert(0, s2[-1])
for _ in range(int(input())):
	y = int(input())
	y1 = y % n
	y2 = y % m
	ans = ''.join(s1[y1] + s2[y2])
	print(ans)


ar = []
for x in input().split(' '):
	ar.append(int(x))
first = list(input().split(' '))
second = list(input().split(' '))
count = 0
count2 = 0
ch = 0
qwe = first[0] + second[0]
finAr = []
while True:
	temp = ''
	temp2 = ''
	if count < len(first):
		temp = first[count]
	else:
		count = 0
		temp = first[count]
	if count2 < len(second):
		temp2 = second[count2]
	else:
		count2 = 0
		temp2 = second[count2]
	if count == 0 and count2 == 0:
		if ch != 0:
			break
		else:
			ch = 1
	finAr.append(temp + temp2)
	count = count + 1
	count2 = count2 + 1
el = int(input())
for x in range(el):
	n = int(input())
	print(finAr[(n - 1) % len(finAr)])


(n, m) = list(map(int, input().split()))
arr1 = list(map(str, input().split()))
arr2 = list(map(str, input().split()))
for _ in range(int(input())):
	k = int(input())
	zz = k % n
	zzz = k % m
	print(f'{arr1[zz - 1]}{arr2[zzz - 1]}')


(n1, n2) = map(int, input().split())
s1 = list(input().split())
s2 = list(input().split())
q = int(input())
for _ in range(q):
	num = int(input())
	p = num % n1
	if p == 0:
		st1 = s1[-1]
	else:
		st1 = s1[p - 1]
	q = num % n2
	if q == 0:
		st2 = s2[-1]
	else:
		st2 = s2[q - 1]
	print(st1 + st2)


(a, b) = map(int, input().split())
l = list(map(str, input().split()))
m = list(map(str, input().split()))
n = int(input())
for i in range(n):
	s = int(input())
	y = s % a
	z = s % b
	k = l[y - 1] + m[z - 1]
	print(k)


from collections import deque

def foo(x):
	rs = x % n
	rt = x % m
	s.rotate(-1 * rs)
	t.rotate(-1 * rt)
	print(''.join([s[0], t[0]]))
	s.rotate(rs)
	t.rotate(rt)
(n, m) = (int(x) for x in input().split())
s = deque(input().split())
t = deque(input().split())
test = int(input())
for each in range(test):
	foo(int(input()) - 1)


from sys import exit as sys_return
(len_first, len_second) = map(int, input().split())
(first, second) = (input().split(), input().split())
amount = int(input())
while amount != 0:
	amount -= 1
	year = int(input())
	print(first[year % len_first - 1] + second[year % len_second - 1])


(n, m) = map(int, input().split())
l = list(input().split())
k = list(input().split())
q = int(input())
for t in range(q):
	x = int(input())
	a = x % n
	b = x % m
	print(l[a - 1] + k[b - 1])


(n, m) = map(int, input().split())
nstrings = list(map(str, input().split()))
mstrings = list(map(str, input().split()))
count = int(input())
for x in range(count):
	item = int(input())
	print(f'{nstrings[item % n - 1]}{mstrings[item % m - 1]}')


(x, y) = map(int, input().split())
l1 = list(map(str, input().split()))
l2 = list(map(str, input().split()))
for _ in range(int(input())):
	k = int(input())
	print(l1[k % x - 1], end='')
	print(l2[k % y - 1])


(n, m) = map(int, input().split())
s = input().split()
t = input().split()
q = int(input())
mass = ''
for i in range(q):
	y = int(input())
	if y <= n:
		mass += s[y - 1]
	else:
		mass += s[y % n - 1]
	if y <= m:
		mass += t[y - 1] + ' '
	else:
		mass += t[y % m - 1] + ' '
mass = mass.split()
for i in range(q):
	print(mass[i])


ninput = input()
ninput = ninput.split()
n = int(ninput[0])
m = int(ninput[1])
strOne = input()
strOne = strOne.split()
strTwo = input()
strTwo = strTwo.split()
interations = int(input())
while interations > 0:
	interations = interations - 1
	year = int(input())
	if year == n:
		yearPosOne = int(year - 1)
	elif year > n:
		yearPosOne = int(year % n - 1)
	else:
		yearPosOne = int(year - 1)
	if year == m:
		yearPosTwo = int(year - 1)
	elif year > m:
		yearPosTwo = int(year % m - 1)
	else:
		yearPosTwo = int(year - 1)
	print(strOne[yearPosOne] + strTwo[yearPosTwo])


(n, m) = map(int, input().split())
a = list(map(str, input().split()))
b = list(map(str, input().split()))
test = int(input())
for temp in range(test):
	z = int(input())
	print(a[z % len(a) - 1] + b[z % len(b) - 1])


(n, m) = map(int, input().split())
first = list(map(str, input().split()))
last = list(map(str, input().split()))
t = int(input())
for _ in range(t):
	x = int(input())
	a = x % n - 1
	b = x % m - 1
	string = first[a] + last[b]
	print(string)


(n, m) = map(int, input().split())
l1 = list(map(str, input().split()))
l2 = list(map(str, input().split()))
n1 = int(input())
while n1 > 0:
	x = int(input())
	i1 = x % n
	i2 = x % m
	if i1 == 0:
		i1 = n
	if i2 == 0:
		i2 = m
	print(l1[i1 - 1] + l2[i2 - 1])
	n1 -= 1


(n, m) = map(int, input().split())
s = input().split()
t = input().split()
q = int(input())
resultList = []
for _ in range(q):
	k = int(input())
	resultList.append(s[k % n - 1] + t[k % m - 1])
for x in resultList:
	print(x)


(len_1, len_2) = [int(i) for i in input().split()]
(lst_1, lst_2) = (input().split(), input().split())
for i in range(int(input())):
	date = int(input())
	print(lst_1[date % len_1 - 1] + lst_2[date % len_2 - 1])


(n, m) = map(int, input().split())
strings1 = list(map(str, input().split()))
strings2 = list(map(str, input().split()))
q = int(input())
l = []
for i in range(q):
	y = int(input())
	if y % len(strings1) == 0:
		x = len(strings1) - 1
	else:
		x = y % len(strings1) - 1
	if y % len(strings2) == 0:
		r = len(strings2) - 1
	else:
		r = y % len(strings2) - 1
	l.append([strings1[x], strings2[r]])
for i in l:
	print(i[0] + i[1])


from sys import stdin as si, stdout as so
(n, m) = (int(i) for i in si.readline().split())
s = si.readline().split()
t = si.readline().split()
q = int(si.readline())
for i in range(q):
	qi = int(si.readline())
	so.write(s[(qi - 1) % n] + t[(qi - 1) % m] + '\n')
so.flush()


def main():
	(list_one_count, list_two_count) = map(int, input().split())
	list_one = input().split()
	list_two = input().split()
	year_count = int(input())
	years = []
	for x in range(year_count):
		years.append(int(input()))
	for y in years:
		print(list_one[(y - 1) % list_one_count] + list_two[(y - 1) % list_two_count])
main()


(n, m) = map(int, input().strip().split(' '))
l = input().strip().split(' ')
l1 = input().strip().split(' ')
for i in range(int(input())):
	b = int(input()) - 1
	r = l[b % n] + l1[b % m]
	print(r)


(n, m) = map(int, input().split())
arr1 = list(map(str, input().split()))
arr2 = list(map(str, input().split()))
t = int(input())
for i in range(t):
	q = int(input())
	print(arr1[q % n - 1] + arr2[q % m - 1])


(n, m) = [int(x) for x in input().split()]
s = [str(x) for x in input().split()]
t = [str(x) for x in input().split()]
q = int(input())
for i in range(q):
	y = int(input())
	print(s[y % len(s) - 1] + t[y % len(t) - 1])


import math
from math import *
from collections import Counter
from operator import itemgetter
import bisect
import datetime
import calendar
ii = lambda : int(input())
iia = lambda : list(map(int, input().split()))
isa = lambda : list(input().split())
(n, m) = iia()
a = isa()
b = isa()
t = ii()
for _ in range(t):
	x = ii()
	print(a[(x - 1) % n] + b[(x - 1) % m])


(n, m) = map(int, input().split())
s = ['a'] + list(input().split())
t = ['a'] + list(input().split())
(s[0], t[0]) = (s[-1], t[-1])
s.pop()
t.pop()
for _ in range(int(input())):
	x = int(input())
	print(s[x % n] + t[x % m])


(n, m) = map(int, input().split())
s1 = list(input().split())
s2 = list(input().split())
q = int(input())
for i in range(q):
	y = int(input())
	print(s1[(y - 1) % n] + s2[(y - 1) % m])


(n, m) = map(int, input().split())
l = input().split()
p = input().split()
for _ in range(int(input())):
	a = int(input()) - 1
	print(l[a % n] + p[a % m])


(n, m) = list(map(int, input().split()))
list1 = [None] * n
list2 = [None] * m
list1 = list(input().split())
list2 = list(input().split())
q = int(input())
while q > 0:
	q -= 1
	y = int(input())
	a = ''
	b = ''
	if y % n == 0:
		a = list1[-1]
	else:
		a = list1[y % n - 1]
	if y % m == 0:
		b = list2[-1]
	else:
		b = list2[y % m - 1]
	print(a + b)


(a, b) = map(int, input().split())
(arr1, arr2) = (list(map(str, input().split())), list(map(str, input().split())))
for i in range(int(input())):
	hi = int(input())
	print(arr1[(hi - 1) % a] + arr2[(hi - 1) % b])


(n, m) = map(int, input().split())
S = list(map(str, input().split()))
T = list(map(str, input().split()))
q = int(input())
for i in range(q):
	y = int(input())
	print(S[y % n - 1] + T[y % m - 1])


from sys import stdin
r = stdin.readline

def main():
	(n, m) = map(int, r().strip().split())
	s = r().strip().split()
	t = r().strip().split()
	queries = int(r())
	for query in range(queries):
		delta = int(r())
		delta -= 1
		print(s[delta % len(s)] + t[delta % len(t)])
main()


(n, m) = map(int, input().strip().split(' '))
s = input().strip().split(' ')
t = input().strip().split(' ')
q = int(input())
for _ in range(q):
	year = int(input())
	(sIndex, tIndex) = (year % n, year % m)
	ans = s[sIndex - 1] + t[tIndex - 1]
	print(ans)


(n, m) = map(int, input().split())
x = input().split()
y = input().split()
t = int(input())
for _ in range(t):
	z = int(input()) - 1
	print(x[z % n] + y[z % m])


(m, n) = input().split(' ')
s = input().split(' ')
t = input().split(' ')
q = int(input())
queries = []
for i in range(q):
	queries.append(int(input()))
m = int(m)
n = int(n)
for query in queries:
	year = s[query % m - 1] + t[query % n - 1]
	print(year)


(n, m) = [int(i) for i in input().split()]
s = []
g = input()
for i in g.split():
	s.append(i)
t = []
g = input()
for i in g.split():
	t.append(i)
q = int(input())
for i in range(q):
	p = int(input())
	print(s[(p - 1) % n] + t[(p - 1) % m])


(n, m) = map(int, input().split())
list1 = list(input().split())
list2 = list(input().split())

def f(list1, list2, n):
	if n > len(list1):
		a = n % len(list1) - 1
	else:
		a = n - 1
	if n > len(list2):
		b = n % len(list2) - 1
	else:
		b = n - 1
	print(list1[a] + list2[b])
q = int(input())
for i in range(0, q):
	x = int(input())
	f(list1, list2, x)


(n, m) = tuple(map(int, input().split()))
s = input().split()
t = input().split()
q = int(input())
l = [0] * q
for i in range(0, q):
	l[i] = int(input())
for j in l:
	x = j % n
	y = j % m
	print(s[x - 1] + t[y - 1])


(n, k) = input().split()
n = int(n)
k = int(k)
a = [i for i in input().split()]
b = [i for i in input().split()]
q = int(input())
while q != 0:
	q -= 1
	year = int(input())
	year -= 1
	print(a[year % n] + b[year % k])


(n, m) = map(int, input().split())
L = input().split()
M = input().split()
q = int(input())
for _ in range(q):
	year = int(input())
	year -= 1
	print(L[year % n] + M[year % m])


(n, m) = map(int, input().split())
s1 = input().split()
s2 = input().split()
q = int(input())
for i in range(q):
	a = int(input())
	print(s1[a % n - 1] + s2[a % m - 1])


s1 = input().split()
s2 = input().split()
s3 = input().split()
n = int(input())
while n > 0:
	s = ''
	n = n - 1
	m = int(input())
	x1 = 0
	x2 = 0
	x1 = m % int(s1[0])
	x2 = m % int(s1[1])
	a = s2[x1 - 1]
	b = s3[x2 - 1]
	s = s + a + b
	print(s)


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
s = input().split()
t = input().split()
q = int(input())
for _ in range(q):
	y = int(input())
	print(s[(y - 1) % n] + t[(y - 1) % m])


p = input().split()
n = int(p[0])
m = int(p[1])
ns = input().split()
ms = input().split()
q = int(input())
for _ in range(q):
	x = int(input())
	print(ns[x % n - 1] + ms[x % m - 1])


(n, m) = map(int, input().split())
a = list(map(str, input().split()))
b = list(map(str, input().split()))
q = int(input())
for i in range(q):
	n = int(input())
	l = n % len(a)
	r = n % len(b)
	print(a[l - 1] + b[r - 1])


(n, m) = map(int, input().split())
s = list(input().split())
t = list(input().split())
for i in range(int(input())):
	q = int(input())
	s1 = q % n
	t1 = q % m
	print(s[s1 - 1] + t[t1 - 1])


import sys
from functools import partial
from math import sqrt

def abs(x):
	if x < 0:
		return -x
	return x

def bin_search(f, f_derivative, x, is_min=True):
	pass

def longest_zipline(w, g, h, x):
	return sqrt(g ** 2 + x ** 2) + sqrt(h ** 2 + (w - x) ** 2)

def lz_derivative(w, g, h, r, x):
	return x / sqrt(g ** 2 + x ** 2) + (x - w) / sqrt(h ** 2 + (w - x) ** 2)

def prep(temp, l):
	if temp == 0:
		temp = len(l) - 1
	else:
		temp -= 1
	return temp

def gapja(s, t, year):
	result = s[prep(year % len(s), s)] + t[prep(year % len(t), t)]
	return result
for (i, line) in enumerate(sys.stdin):
	if i == 0:
		continue
	elif i == 1:
		s = line.strip().split()
	elif i == 2:
		t = line.strip().split()
	elif i == 3:
		continue
	else:
		year = int(line)
		print(gapja(s, t, year))


import math, itertools, fractions, heapq, collections, bisect, sys, queue, copy
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def LS():
	return sys.stdin.readline().split()

def S():
	return input()

def main():
	(a, b) = LI()
	la = LS()
	lb = LS()
	ans = []
	n = I()
	for _ in range(n):
		k = I()
		k -= 1
		x = la[k % a]
		x += lb[k % b]
		ans.append(x)
	for x in ans:
		print(x)
main()


ln = input().split(' ')
(ln[0], ln[1]) = (int(ln[0]), int(ln[1]))
aa = input().split(' ')
bb = input().split(' ')
x = int(input())
while x > 0:
	x -= 1
	y = int(input())
	print(aa[y % ln[0] - 1] + bb[y % ln[1] - 1])


(n, m) = [int(k) for k in input().strip().split(' ')]
s = input().split(' ')
t = input().split(' ')
q = int(input())
for i in range(q):
	a = int(input()) - 1
	print(s[a % n] + t[a % m])


(n, m) = map(int, input().split())
first = input()
arr = first.split(' ')
sec = input()
arr1 = sec.split(' ')
q = int(input())
for i in range(q):
	x = int(input())
	rem = ''
	if x <= n and x <= m:
		rem += arr[x - 1]
		rem += arr1[x - 1]
		print(rem)
	elif n < x <= m:
		temp = x % n
		rem += arr[temp - 1]
		rem += arr1[x - 1]
		print(rem)
	elif n >= x > m:
		temp = x % m
		rem += arr[x - 1]
		rem += arr1[temp - 1]
		print(rem)
	else:
		temp1 = x % n
		temp2 = x % m
		rem += arr[temp1 - 1]
		rem += arr1[temp2 - 1]
		print(rem)


def main():
	try:
		nm = input().split(' ')
		n = int(nm[0])
		m = int(nm[1])
		n_arr = [str(x) for x in input().split(' ')]
		m_arr = [str(x) for x in input().split(' ')]
		num = int(input())
		for i in range(num):
			year = int(input())
			n_arr_index = year % n - 1
			m_arr_index = year % m - 1
			print(n_arr[n_arr_index] + m_arr[m_arr_index])
	except Exception as e:
		print(e)
main()


from math import *
sInt = lambda : int(input())
mInt = lambda : map(int, input().split())
lInt = lambda : list(map(int, input().split()))
(n, m) = mInt()
a = list(map(str, input().split()))
b = list(map(str, input().split()))
t = sInt()
for _ in range(t):
	q = sInt()
	print(a[q % n - 1] + b[q % m - 1])


(n, m) = map(int, input().split())
a = list(map(str, input().split()))
b = list(map(str, input().split()))
t = int(input())
for i in range(t):
	x = int(input())
	temp1 = x
	temp2 = x
	if x > n:
		temp1 = x % n
	print(a[temp1 - 1], end='')
	if x > m:
		temp2 = x % m
	print(b[temp2 - 1])


(n, m) = [int(x) for x in input().split()]
s1 = input().split()
s2 = input().split()
q = int(input())
for i in range(q):
	f = int(input()) - 1
	f1 = f % len(s1)
	f2 = f % len(s2)
	print(s1[f1] + s2[f2])


(n, m) = map(int, input().split())
l1 = list(map(str, input().split()))
l2 = list(map(str, input().split()))
q = int(input())
for i in range(q):
	p = int(input())
	le1 = p % len(l1)
	le2 = p % len(l2)
	s = l1[le1 - 1] + l2[le2 - 1]
	print(s)


x = input()
y = x.split(' ')
s1 = input()
s2 = input()
s3 = s1.split(' ')
s4 = s2.split(' ')
z = int(input())
while z > 0:
	u = int(input())
	w = u
	v = u
	w = w % int(y[0])
	v = v % int(y[1])
	print(s3[w - 1] + s4[v - 1])
	z = z - 1


(n, m) = list(map(int, input().strip().split()))
l = input().split()
t = input().split()
for j in range(int(input())):
	k = int(input())
	print(l[k % n - 1], end='')
	print(t[k % m - 1])


l = input().split()
n = int(l[0])
m = int(l[1])
l = input().split()
ok = input().split()
q = int(input())
for i in range(q):
	z = int(input())
	z -= 1
	print(l[z % n] + ok[z % m])


(m, n) = input('').split(' ')
a = int(m)
b = int(n)
s = input('').split(' ')
t = input('').split(' ')
q = int(input(''))
i = 1
while i <= q:
	y = int(input(''))
	d = y % a - 1
	e = y % b - 1
	g = s[d]
	h = t[e]
	print(g + h)
	i += 1


mn = input()
strm = ''
strn = ''
sgn = 0
for j in mn:
	if j != ' ' and j != '\n' and (sgn == 0):
		strm += j
	if j != ' ' and j != '\n' and (sgn == 1):
		strn += j
	if j == ' ':
		sgn = 1
(m, n) = (int(strm), int(strn))
strs = input() + '\n'
strt = input() + '\n'
s = []
t = []
now = ''
for i in strs:
	if i != ' ' and i != '\n':
		now += i
	if i == ' ' or i == '\n':
		s.append(now)
		now = ''
now = ''
for i in strt:
	if i != ' ' and i != '\n':
		now += i
	if i == ' ' or i == '\n':
		t.append(now)
		now = ''
q = int(input())
year = 2020
for _ in range(q):
	year = int(input())
	s1 = (year - 1) % (m * n) % m
	t1 = (year - 1) % (m * n) % n
	print(s[s1] + t[t1])


(lena, lenb) = map(int, input().split())
a = input().split()
b = input().split()
limit = int(input())
for i in range(limit):
	n = int(input())
	a1 = n % lena
	b1 = n % lenb
	print(a[a1 - 1] + b[b1 - 1])


l = list(map(int, input().split()))
n = l[0]
m = l[1]
g = list(map(str, input().split()))
h = list(map(str, input().split()))
t = int(input())
for i in range(t):
	a = int(input())
	b = g[a % n - 1]
	c = h[a % m - 1]
	print(b + c)


(x, y) = map(int, input().split())
A = list(map(str, input().split(' ')))
B = list(map(str, input().split(' ')))
z = int(input())
while z > 0:
	n = int(input())
	n = n - 1
	print(A[n % x] + B[n % y])
	z -= 1


a = input().split(' ')
(n, m) = (int(a[0]), int(a[1]))
b = input().split(' ')
c = input().split(' ')
t = int(input())
s = []
for i in range(t):
	p = int(input())
	u = []
	(x, y) = (p % n, p % m)
	u.append(b[x - 1])
	u.append(c[y - 1])
	s.append(u)
for j in range(t):
	print(''.join(s[j]))


arrayLegths = input().split(' ')
for i in range(0, len(arrayLegths)):
	arrayLegths[i] = int(arrayLegths[i])
s1 = input().split(' ')
s2 = input().split(' ')
q = int(input())
for _ in range(q):
	y = int(input()) - 1
	print(s1[y % arrayLegths[0]] + s2[y % arrayLegths[1]])


length = input().split(' ')
nlen = int(length[0])
mlen = int(length[1])
strn = input().split(' ')
strm = input().split(' ')
n = int(input())
for _ in range(n):
	year = int(input())
	nyear = year % nlen - 1
	myear = year % mlen - 1
	print(strn[nyear] + strm[myear])


(a, b) = map(int, input().split())
s = list(map(str, input().split()))
t = list(map(str, input().split()))
for i in range(int(input())):
	n = int(input())
	print(s[(n - 1) % a] + t[(n - 1) % b])


(n, m) = list(map(int, input().split()))
n_words = input().split()
m_words = input().split()
n_word_dict = {}
m_word_dict = {}
for (i, word) in enumerate(n_words, start=1):
	n_word_dict[i % n] = word
for (i, word) in enumerate(m_words, start=1):
	m_word_dict[i % m] = word
q = int(input())
for i in range(q):
	year = int(input())
	s1 = n_word_dict[year % n]
	s2 = m_word_dict[year % m]
	print(s1 + s2)


def nam(a, b, x):
	p = x % len(a)
	q = x % len(b)
	print(a[p - 1] + b[q - 1])
(n, m) = list(map(int, input().split()))
a = list(map(str, input().split()))
b = list(map(str, input().split()))
q = int(input())
c = []
for i in range(q):
	c.append(int(input()))
for i in range(q):
	nam(a, b, c[i])


(n, m) = map(int, input().split())
a = list(input().split())
b = list(input().split())
q = int(input())
for qy in range(q):
	year = int(input())
	print(a[(year - 1) % len(a)] + b[(year - 1) % len(b)])


nums = input().split(' ')
n = int(nums[0])
m = int(nums[1])
s = input().split(' ')
t = input().split(' ')
q = int(input())
for k in range(q):
	y = int(input())
	print(s[(y - 1) % n] + t[(y - 1) % m])


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
masn = list(map(str, input().split()))
masm = list(map(str, input().split()))
mas = []
ans = []
for i in range(int(input())):
	i = int(input()) - 1
	print(masn[i % n] + masm[i % m])


(x, y) = map(int, input().split())
a = list(input().split())
b = list(input().split())
t = int(input())
for _ in range(t):
	n = int(input()) - 1
	print(a[n % x] + b[n % y])


(n, m) = [int(a) for a in input().split()]
s = input().split()
t = input().split()
k = int(input())
output = ''
for i in range(k):
	year = int(input())
	si = year % n
	ti = year % m
	if si == 0:
		si = n
	if ti == 0:
		ti = m
	output = output + s[si - 1] + t[ti - 1] + '\n'
print(output)


[n, m] = [int(x) for x in input().split()]
N = [x for x in input().split()]
M = [x for x in input().split()]
q = int(input())
Q = []
for i in range(q):
	Q.append(int(input()))
for i in Q:
	print(N[i % n - 1] + M[i % m - 1])


import math
(llen, rlen) = list(map(int, input().strip().split(' ')))
left = list(map(str, input().strip().split(' ')))
right = list(map(str, input().strip().split(' ')))
k = int(input())
for i in range(k):
	ind = int(input()) - 1
	print(left[ind % llen] + right[ind % rlen])


from sys import stdin, stdout
read = lambda : map(int, stdin.readline().split())
I = lambda : stdin.readline()
(n, m) = read()
s = I().split()
t = I().split()
ans = ''
for i in range(int(I())):
	y = int(I()) - 1
	ans += s[y % n] + t[y % m] + '\n'
print(ans)


(a1, a2) = map(int, input().split())
b1 = input().split()
b2 = input().split()
for i in range(int(input())):
	c = int(input())
	print(b1[(c - 1) % a1] + b2[(c - 1) % a2])


(a, b) = input().split()
a = int(a)
b = int(b)
lst1 = input().split()
lst2 = input().split()
nn = int(input())
for i in range(0, nn):
	n = int(input())
	print(lst1[n % a - 1] + lst2[n % b - 1])


def solve(n, m, arr_s, arr_t, years):
	str_years = list()
	for year in years:
		str_years.append(arr_s[(year - 1) % n] + arr_t[(year - 1) % m])
	return '\n'.join(str_years)
(n, m) = map(int, input().split(' '))
arr_s = input().split(' ')
arr_t = input().split(' ')
q = int(input())
years = list()
for _ in range(0, q):
	year = int(input())
	years.append(year)
print(solve(n, m, arr_s, arr_t, years))


n = input()
a1 = input().split()
a2 = input().split()
b = int(input())
for i in range(b):
	c = int(input())
	d1 = c % len(a1)
	d2 = c % len(a2)
	print(a1[d1 - 1] + a2[d2 - 1])


input()
s = input().split()
t = input().split()
for _ in range(int(input())):
	y = int(input()) - 1
	print(s[y % len(s)] + t[y % len(t)])


(n, m) = [int(x) for x in input().split(' ')]
s = input().split(' ')
t = input().split(' ')
q = int(input())
for y in range(q):
	year = int(input())
	(nmod, mmod) = (year % n, year % m)
	if nmod > 0:
		nmod -= 1
	else:
		nmod = n - 1
	if mmod > 0:
		mmod -= 1
	else:
		mmod = m - 1
	print(s[nmod], t[mmod], sep='')


x = input()
(l1, l2) = x.split()
list1 = input()
list2 = input()
list1 = list1.split()
list2 = list2.split()
query = int(input())
for i in range(query):
	year = int(input())
	name = list1[year % int(l1) - 1] + list2[year % int(l2) - 1]
	print(name)


(n, m) = map(int, input().split())
s = input().split()
t = input().split()
q = int(input())
for qq in range(q):
	y = int(input()) - 1
	a = y % n
	b = y % m
	year = s[a] + t[b]
	print(year)


(n, m) = map(int, input().split())
st1 = input().split()
st2 = input().split()
q = int(input())
for i in range(q):
	y = int(input())
	y1 = (y - 1) % n
	y2 = (y - 1) % m
	print(st1[y1] + st2[y2])


(n, m) = map(int, input().split())
a = input().split()
b = input().split()
t = int(input())
for i in range(t):
	q = int(input()) - 1
	print(a[q % n], b[q % m], sep='')


(n, m) = map(int, input().split())
x = [str(n) for n in input().split()]
y = [str(n) for n in input().split()]
for _ in range(int(input())):
	p = int(input())
	print(x[p % n - 1] + y[p % m - 1])


def dkwpwn(num, str1, str2):
	(len1, len2) = (len(str1), len(str2))
	output = ''
	output += str1[num - len1 * (num // len1) - 1]
	output += str2[num - len2 * (num // len2) - 1]
	return output
useless = list(map(int, input().split()))
str1 = list(input().split())
str2 = list(input().split())
q = int(input())
for _ in range(q):
	num = int(input())
	print(dkwpwn(num, str1, str2))


(n, m) = map(int, input().split())
s = list(map(str, input().split()))
t = list(map(str, input().split()))
for i in range(int(input())):
	l = int(input())
	y = (l - 1) % n
	u = (l - 1) % m
	print(s[y] + t[u])


(a, b) = input().split()
n = int(a)
m = int(b)
l1 = []
l2 = []
l1 = list(input().split())
l2 = list(input().split())
for __ in range(int(input())):
	p = int(input())
	x = (p - 1) % n
	y = (p - 1) % m
	x = l1[x] + l2[y]
	print(x)


lis = []
lis1 = []
(n, m) = input().split()
n = int(n)
m = int(m)
lis = list(map(str, input().split()))
d = lis.pop()
lis.insert(0, d)
lis1 = list(map(str, input().split()))
d = lis1.pop()
lis1.insert(0, d)
k = int(input())
for _ in range(0, k):
	c = int(input())
	print(lis[c % n] + lis1[c % m])


(n, m) = map(int, input().split())
s1 = input().split()
s2 = input().split()
for _ in range(int(input())):
	a = int(input())
	print(s1[a % n - 1] + s2[a % m - 1])


(n, m) = input().split()
n = int(n)
m = int(m)
l1 = []
l2 = []
s1 = input()
l1 = list(s1.split(' '))
s2 = input()
l2 = list(s2.split(' '))
giv = int(input())
while giv != 0:
	a = input()
	a = int(a)
	new_n = a % n
	new_m = a % m
	print(l1[new_n - 1] + l2[new_m - 1])
	giv = giv - 1


n = list(map(int, input().split()))
x = list(map(str, input().split()))
y = list(map(str, input().split()))
q = input()
q = int(q)
for i in range(0, q):
	a = input()
	a = int(a)
	a = a - 1
	b = a % n[1]
	a = a % n[0]
	print(x[a] + y[b])


try:
	(a, b) = map(int, input().split())
	l = list(map(str, input().split()))
	m = list(map(str, input().split()))
	for i in range(int(input())):
		n = int(input())
		print(l[(n - 1) % a] + m[(n - 1) % b])
except:
	pass


try:
	while True:
		(n, m) = map(int, input().split())
		nlist = list(map(str, input().split()))
		mlist = list(map(str, input().split()))
		q = int(input())
		for i in range(q):
			year = int(input())
			nrem = year % n
			mrem = year % m
			if nrem == 0:
				nname = nlist[-1]
			else:
				nname = nlist[nrem - 1]
			if mrem == 0:
				mname = mlist[-1]
			else:
				mname = mlist[mrem - 1]
			print(nname + mname)
except EOFError:
	pass


import sys

def func():
	(n, m) = tuple(map(int, sys.stdin.readline().split(' ')))
	s = sys.stdin.readline().strip().split(' ')
	t = sys.stdin.readline().strip().split(' ')
	qs = int(sys.stdin.readline())
	while qs:
		qs -= 1
		year = int(sys.stdin.readline())
		_s = (year - 1) % n
		_t = (year - 1) % m
		print(f'{s[_s]}{t[_t]}')
func()
_STATEMENT = '\nA. New Year and Naming\ntime limit per test\n1 second\nmemory limit per test\n1024 megabytes\ninput\nstandard input\noutput\nstandard output\n\nHappy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let\'s briefly look at the Gapja system, which is traditionally used in Korea to name the years.\n\nThere are two sequences of 𝑛\nstrings 𝑠1,𝑠2,𝑠3,…,𝑠𝑛 and 𝑚 strings 𝑡1,𝑡2,𝑡3,…,𝑡𝑚\n\n. These strings contain only lowercase letters. There might be duplicates among these strings.\n\nLet\'s call a concatenation of strings 𝑥\nand 𝑦 as the string that is obtained by writing down strings 𝑥 and 𝑦\n\none right after another without changing the order. For example, the concatenation of the strings "code" and "forces" is the string "codeforces".\n\nThe year 1 has a name which is the concatenation of the two strings 𝑠1\nand 𝑡1\n\n. When the year increases by one, we concatenate the next two strings in order from each of the respective sequences. If the string that is currently being used is at the end of its sequence, we go back to the first string in that sequence.\n\nFor example, if 𝑛=3,𝑚=4,𝑠=\n{"a", "b", "c"}, 𝑡=\n\n{"d", "e", "f", "g"}, the following table denotes the resulting year names. Note that the names of the years may repeat.\n\nYou are given two sequences of strings of size 𝑛\nand 𝑚 and also 𝑞\n\nqueries. For each query, you will be given the current year. Could you find the name corresponding to the given year, according to the Gapja system?\nInput\n\nThe first line contains two integers 𝑛,𝑚\n(1≤𝑛,𝑚≤20\n\n).\n\nThe next line contains 𝑛\nstrings 𝑠1,𝑠2,…,𝑠𝑛. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least 1 and at most 10\n\n.\n\nThe next line contains 𝑚\nstrings 𝑡1,𝑡2,…,𝑡𝑚. Each string contains only lowercase letters, and they are separated by spaces. The length of each string is at least 1 and at most 10\n\n.\n\nAmong the given 𝑛+𝑚\n\nstrings may be duplicates (that is, they are not necessarily all different).\n\nThe next line contains a single integer 𝑞\n(1≤𝑞≤2020\n\n).\n\nIn the next 𝑞\nlines, an integer 𝑦 (1≤𝑦≤109\n\n) is given, denoting the year we want to know the name for.\nOutput\n\nPrint 𝑞\n\nlines. For each line, print the name of the year as per the rule described above.\nExample\nInput\n\n10 12\nsin im gye gap eul byeong jeong mu gi gyeong\nyu sul hae ja chuk in myo jin sa o mi sin\n14\n1\n2\n3\n4\n10\n11\n12\n13\n73\n2016\n2017\n2018\n2019\n2020\n\nOutput\n\nsinyu\nimsul\ngyehae\ngapja\ngyeongo\nsinmi\nimsin\ngyeyu\ngyeyu\nbyeongsin\njeongyu\nmusul\ngihae\ngyeongja\n\nNote\n\nThe first example denotes the actual names used in the Gapja system. These strings usually are either a number or the name of some animal.\n'


(n, m) = map(int, input().split())
l1 = input().split()
l2 = input().split()
for i in [0] * int(input()):
	a = int(input())
	print(l1[a % n - 1] + l2[a % m - 1])


mn = input()
mn = mn.split()
m = int(mn[0])
n = int(mn[1])
s = input()
t = input()
t = t.split()
s = s.split()
q = int(input())
while q > 0:
	y = int(input())
	rem1 = y % m
	rem2 = y % n
	print(s[rem1 - 1] + t[rem2 - 1])
	q -= 1


s = input().split()
k = input().split()
i = input().split()
a = int(input())
g = []
l = 0
for d in range(1, a + 1):
	l = int(input())
	g.append(l)
for h in range(0, len(g)):
	print(k[(g[h] - 1) % int(s[0])] + i[(g[h] - 1) % int(s[1])])


T_ON = 0
DEBUG_ON = 0
MOD = 998244353

def solve():
	(n, m) = read_ints()
	S = input().split()
	T = input().split()
	q = read_int()
	for _ in range(q):
		y = read_int()
		a = y % n
		b = y % m
		print(S[a - 1] + T[b - 1])

def main():
	T = read_int() if T_ON else 1
	for i in range(T):
		solve()

def debug(*xargs):
	if DEBUG_ON:
		print(*xargs)
from collections import *
import math
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def read_int():
	return int(input())

def read_ints():
	return list(map(int, input().split()))

def print_nums(nums):
	print(' '.join(map(str, nums)))

def YES():
	print('YES')

def Yes():
	print('Yes')

def NO():
	print('NO')

def No():
	print('No')

def fib(n):
	(a, b) = (0, 1)
	for _ in range(n):
		(a, b) = (b, a + b)
	return a

def fib_ns(n):
	assert n >= 1
	f = [0 for _ in range(n + 1)]
	f[0] = 0
	f[1] = 1
	for i in range(2, n + 1):
		f[i] = f[i - 1] + f[i - 2]
	return f

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def lcm(a, b):
	d = gcd(a, b)
	return a * b // d

def xgcd(a, b):
	(x0, x1, y0, y1) = (0, 1, 1, 0)
	while a != 0:
		((q, a), b) = (divmod(b, a), a)
		(y0, y1) = (y1, y0 - q * y1)
		(x0, x1) = (x1, x0 - q * x1)
	return (b, x0, y0)

def modinv(a, m):
	(g, x, _) = xgcd(a, m)
	if g != 1:
		raise Exception('gcd(a, m) != 1')
	return x % m

def mod_add(x, y):
	x += y
	while x >= MOD:
		x -= MOD
	while x < 0:
		x += MOD
	return x

def mod_mul(x, y):
	return x * y % MOD

def mod_pow(x, y):
	if y == 0:
		return 1
	if y % 2:
		return mod_mul(x, mod_pow(x, y - 1))
	p = mod_pow(x, y // 2)
	return mod_mul(p, p)

def mod_inv(y):
	return mod_pow(y, MOD - 2)

def mod_div(x, y):
	return mod_mul(x, mod_inv(y))

def is_prime(n):
	if n == 1:
		return False
	for i in range(2, int(n ** 0.5) + 1):
		if n % i:
			return False
	return True

def gen_primes(n):
	P = [True for _ in range(n + 1)]
	P[0] = P[1] = False
	for i in range(int(n ** 0.5) + 1):
		if P[i]:
			for j in range(2 * i, n + 1, i):
				P[j] = False
	return P
main()


def map_to_list(list_, fun):
	for i in range(len(list_)):
		list_[i] = fun(list_[i])

def spaced_string_to_list(count, str_):
	arr = []
	char_index = 0
	word = ''
	for arr_index in range(count):
		while not (char_index >= len(str_) or str_[char_index] == ' '):
			word += str_[char_index]
			char_index += 1
		arr.append(word)
		word = ''
		char_index += 1
	return arr

def spaced_string_to_list(count, str_):
	arr = []
	char_index = 0
	word = ''
	for arr_index in range(count):
		while not (char_index >= len(str_) or str_[char_index] == ' '):
			word += str_[char_index]
			char_index += 1
		arr.append(word)
		word = ''
		char_index += 1
	return arr

def spaced_numbers_str_to_list(amount, str_numbers):
	numbers_list = spaced_string_to_list(amount, str_numbers)
	map_to_list(numbers_list, int)
	return numbers_list

def gapja_years(first_names, second_names, year):
	i = year - 1
	x = i - len(first_names) * (i // len(first_names))
	y = i - len(second_names) * (i // len(second_names))
	return first_names[x] + second_names[y]
names_arrs_amounts = spaced_numbers_str_to_list(2, input())
first_names = spaced_string_to_list(names_arrs_amounts[0], input())
second_names = spaced_string_to_list(names_arrs_amounts[1], input())
years_amount = int(input())
years = []
for i in range(years_amount):
	years.append(int(input()))
t_arr = []
for i in range(len(years)):
	print(gapja_years(first_names, second_names, years[i]))


num = input().split()
num = [int(x) for x in num]
list1 = input().split()
list2 = input().split()
need_year = int(input())
year_list = []
for i in range(need_year):
	year_list.append(int(input()))
work_list1 = [year_list[i] % num[0] for i in range(need_year)]
work_list2 = [year_list[i] % num[1] for i in range(need_year)]
for i in range(need_year):
	if work_list1[i] == 0:
		work_list1[i] = list1[-1]
	else:
		work_list1[i] = list1[work_list1[i] - 1]
for i in range(need_year):
	if work_list2[i] == 0:
		work_list2[i] = list2[-1]
	else:
		work_list2[i] = list2[work_list2[i] - 1]
work_list = [work_list1[i] + work_list2[i] for i in range(need_year)]
for i in work_list:
	print(i)


(n, m) = map(int, input().split())
str1 = list(map(str, input().split()))
str2 = list(map(str, input().split()))
q = int(input())
for i in range(q):
	y = int(input())
	p = x = y
	while p > n:
		p %= n
	while x > m:
		x %= m
	ans = str1[p - 1] + str2[x - 1]
	print(ans)


(n, m) = map(int, input().split())
an = list(input().split())
am = list(input().split())
Q = int(input())
for q in range(Q):
	y = int(input())
	name = an[y % n - 1] + am[y % m - 1]
	print(name)


from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline

def factors(n):
	return sorted(list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))))

def li():
	return [int(i) for i in input().rstrip('\n').split(' ')]

def st():
	return input().rstrip('\n')

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n').split(' ')]

def li3():
	return [int(i) for i in input().rstrip('\n')]
(n, m) = li()
s = li2()
t = li2()
q = val()
for i in range(q):
	temp = val()
	print(s[(temp % len(s) - 1) % len(s)] + t[(temp % len(t) - 1) % len(t)])


input()
s1 = input().split()
s2 = input().split()
n = int(input())

def fox(s1, s2):
	k = int(input()) - 1
	print(s1[k % len(s1)] + s2[k % len(s2)])
for _ in range(n):
	fox(s1, s2)


input()
n = input().split()
m = input().split()
q = int(input())
years = []

def get_year_name(y):
	global n, m
	n_b = y % len(n)
	if len(n) == n_b:
		n_b = 0
	else:
		n_b -= 1
	m_b = y % len(m)
	if len(m) == m_b:
		m_b = 0
	else:
		m_b -= 1
	return n[n_b] + m[m_b]
for i in range(q):
	years.append(int(input()))
for year in years:
	print(get_year_name(year))


(n, m) = list(map(int, input().split()))
arr_n = list(map(str, input().split()))
arr_m = list(map(str, input().split()))
q = int(input())
for _ in range(q):
	y = int(input()) - 1
	year_name = arr_n[y % n] + arr_m[y % m]
	print(year_name)


def nod(a, b):
	while b != 0:
		r = a % b
		a = b
		b = r
	return a

def nok(a, b):
	return a * b // nod(a, b)
(n, m) = map(int, input().split())
num = list(input().split())
spis = list(input().split())
q = int(input())
c = nok(m, n)
nazv = []
j = -1
d = -1
for i in range(c):
	d += 1
	j += 1
	if d == n:
		d = 0
	if j == m:
		j = 0
	nazv.append(num[d] + spis[j])
for i in range(q):
	f = int(input())
	print(nazv[(f - 1) % c])


(n, m) = map(int, input().split())
s = list(map(str, input().split()))
t = list(map(str, input().split()))
q = int(input())
for i in range(q):
	year = int(input())
	s1 = year
	n1 = year
	if year > n:
		s1 = year % n - 1
	else:
		s1 = year - 1
	if year > m:
		n1 = year % m - 1
	else:
		n1 = year - 1
	print(s[s1] + t[n1])


def solve(n, m, s, t, years):
	year_list = list()
	for year in years:
		year_list.append(s[(year - 1) % n] + t[(year - 1) % m])
	return '\n'.join(year_list)
(n, m) = map(int, input().split(' '))
s = input().split(' ')
t = input().split(' ')
q = int(input())
years = list()
for _ in range(q):
	year = int(input())
	years.append(year)
print(solve(n, m, s, t, years))


(n, m) = map(int, input().split())
l1 = input().split()
l2 = input().split()
t = int(input())
for i in range(t):
	g = int(input())
	ans = l1[(g - 1) % n] + l2[(g - 1) % m]
	print(ans)


(n, m) = map(int, input().split())
arr = list(map(str, input().split()))
brr = list(map(str, input().split()))
q = int(input())
for _ in range(q):
	y = int(input())
	if y <= n:
		ind1 = y - 1
	else:
		ind1 = y % n - 1
	if y <= m:
		ind2 = y - 1
	else:
		ind2 = y % m - 1
	print(arr[ind1] + brr[ind2])


(n, m) = map(int, input().split())
lst_n = list(map(str, input().split()))
lst_m = list(map(str, input().split()))
q = int(input())
lst_y = [int(input()) for i in range(q)]
ans = []
for i in range(q):
	combine = lst_n[(lst_y[i] - 1) % n] + lst_m[(lst_y[i] - 1) % m]
	ans.append(combine)
print('\n'.join(ans))


(n, m) = [int(x) for x in input().split()]
a = [str(x) for x in input().split()]
b = [str(x) for x in input().split()]
q = int(input())
for _ in range(q):
	k = int(input())
	x = k % n
	y = k % m
	print(a[x - 1] + b[y - 1])


(l1, l2) = map(int, input().split())
s1 = list(map(str, input().split()))
s2 = list(map(str, input().split()))
t = int(input())
for i in range(t):
	num = int(input())
	print(s1[(num - 1) % l1] + s2[(num - 1) % l2])


(j, k) = map(int, input().split())
year = input().split()
month = input().split()
n = int(input())
s = []
for i in range(n):
	s.append(int(input()))
for i in range(n):
	print(year[s[i] % j - 1] + month[s[i] % k - 1])


def HCF(n, m):
	a = min(n, m)
	b = max(n, m)
	while True:
		t = n % m
		if t == 0:
			break
		n = m
		m = t
	return m
(n, m) = map(int, input().split())
l1 = input().split()
l2 = input().split()
LCM = n * m // HCF(n, m)
d = {}
for i in range(1, LCM + 1):
	d[i] = l1[(i - 1) % n] + l2[(i - 1) % m]
t = int(input())
for i in range(t):
	y = int(input())
	if y % LCM == 0:
		print(d[LCM])
	else:
		print(d[y % LCM])


(n, m) = map(int, input().split())
arr1 = list(input().split())
arr2 = list(input().split())
for _ in range(int(input())):
	x = int(input())
	print(arr1[(x - 1) % n] + arr2[(x - 1) % m])


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
s = input().split()
t = input().split()
q_n = input()
for line in sys.stdin:
	q = int(line) - 1
	print(s[q % n] + t[q % m])


(n, m) = map(int, input().split())
s1 = input().split()
s2 = input().split()
res = []
for _ in range(int(input())):
	x = int(input())
	res.append(s1[x % n - 1] + s2[x % m - 1])
for i in res:
	print(i)


(a, b) = map(int, input().split())
first_list = input().split()
second_list = input().split()
number_q = int(input())

def naming(x):
	f1 = (x - 1) % a
	f2 = (x - 1) % b
	ans = first_list[f1] + second_list[f2]
	print(ans)
for i in range(number_q):
	n = int(input())
	naming(n)


inp = input
li = list
iinp = lambda : int(inp())
ent = lambda : map(int, inp().split())
lient = lambda : li(ent())
(n, m) = ent()
l1 = inp().split(' ')
l2 = inp().split(' ')
q = iinp()
for i in range(q):
	j = iinp()
	res = l1[j % n - 1] + l2[j % m - 1]
	print(res)


source = input().split(' ')
a = int(source[0])
b = int(source[1])
string1 = input().split(' ')
string2 = input().split(' ')
k = int(input())
for i in range(k):
	ans = ''
	year = int(input())
	if year % a == 0:
		ans += string1[a - 1]
	else:
		ans += string1[year % a - 1]
	if year % b == 0:
		ans += string2[b - 1]
	else:
		ans += string2[year % b - 1]
	print(ans)


(n, m) = map(int, input().split())
s1 = input().split()
s2 = input().split()
mm = int(input())
for i in range(mm):
	temp = int(input())
	temp = temp - 1
	print(s1[temp % n] + s2[temp % m])


(n, m) = [int(i) for i in input().split()]
s = input().split()
t = input().split()
q = int(input())
for i in range(q):
	ans = str()
	year = int(input())
	if year % n == 0:
		ans += s[-1]
	else:
		ans += s[year % n - 1]
	if year % m == 0:
		ans += t[-1]
	else:
		ans += t[year % m - 1]
	print(ans)


import os
(n, m) = list(map(int, input().split(' ')))
s = list(map(str, input().split(' ')))
t = list(map(str, input().split(' ')))
q = int(input())
for qq in range(q):
	p = int(input())
	p = p - 1
	s1 = s[p % n]
	s2 = t[p % m]
	print(f'{s1}{s2}')


(n, m) = map(int, input().split())
s = list(input().split())
t = list(input().split())
q = int(input())
result = []
while q > 0:
	year = int(input())
	a = s[year % len(s) - 1]
	b = t[year % len(t) - 1]
	result.append(a + b)
	q -= 1
for i in result:
	print(i)


import math
import cmath
from decimal import *
from fractions import *
(n, m) = map(int, input().split())
s = list(input().split())
t = list(input().split())
q = int(input())
for _ in range(q):
	year = int(input())
	print(s[year % n - 1], end='')
	print(t[year % m - 1])


def solve(x, n, m, L1, L2):
	return L1[(x - 1) % n] + L2[(x - 1) % m]
(n, m) = tuple(map(int, input().split()))
ns = input().split()
ms = input().split()
q = int(input())
ans = [solve(int(input()), n, m, ns, ms) for x in range(q)]
print('\n'.join(ans))


(n, m) = map(int, input().split())
a = input().split()
b = input().split()
q = int(input())
for i in range(0, q):
	year = int(input())
	try:
		corean = a[year - 1] + b[year - 1]
		print(corean)
	except IndexError:
		x = year // n
		y = year // m
		if n == 1 and m == 1:
			corean = a[0] + b[0]
		elif n == 1:
			year2 = year - y * m
			corean = a[0] + b[year2 - 1]
		elif m == 1:
			year1 = year - x * n
			corean = a[year1 - 1] + b[0]
		else:
			year1 = year - x * n
			year2 = year - y * m
			corean = a[year1 - 1] + b[year2 - 1]
		print(corean)


(n, m) = [int(x) for x in input().split(' ')]
s = [x for x in input().split(' ')]
t = [x for x in input().split(' ')]
casos = int(input())
for x in range(casos):
	anio = int(input())
	print(s[anio % n - 1] + t[anio % m - 1])


(n, m) = map(int, input().split())
l = list(input().split())
k = list(input().split())
x = int(input())
for i in range(x):
	a = int(input())
	c = a % n
	d = a % m
	print(l[c - 1] + k[d - 1])


firstLine = input().split()
n = int(firstLine[0])
m = int(firstLine[1])
nString = input().split()
mString = input().split()
q = input()
q = int(q)
yearList = []
for x in range(q):
	y = input()
	yearList.append(y)
yearList = [int(x) for x in yearList]
for year in yearList:
	print(nString[year % n - 1] + mString[year % m - 1])


tmp = input().split()
n = int(tmp[0])
m = int(tmp[1])
nList = input().split()
mList = input().split()
yearList = []
for i in range(int(input())):
	yearList.append(int(input()))
for year in yearList:
	print(nList[year % n - 1] + mList[year % m - 1])


(n, m) = map(int, input().split())
a = list(map(str, input().split()))
b = list(map(str, input().split()))
t = int(input())
for i in range(t):
	v = int(input())
	x = v % len(a)
	y = v % len(b)
	print(a[x - 1] + b[y - 1])


(a, b) = map(int, input().split())
l = []
n = list(input().split())
m = list(input().split())
for i in range(0, int(input())):
	x = int(input())
	(p, q) = (x % a - 1, x % b - 1)
	l.append(n[p] + m[q])
[print(i, end='\n') for i in l]


(n, m) = [int(n) for n in input().split()]
s1 = [item for item in input().split()]
s2 = [item for item in input().split()]
t = int(input())
for i in range(t):
	num = int(input())
	q1 = (num - 1) % n
	q2 = (num - 1) % m
	res = s1[q1] + s2[q2]
	print(res)


(n, m) = map(int, input().split())
s = list(input().split())
t = list(input().split())
l1 = len(s)
l2 = len(t)
q = int(input())
for i in range(q):
	x = int(input())
	half1 = s[x - x // l1 * l1 - 1]
	half2 = t[x - x // l2 * l2 - 1]
	print(half1 + half2)


l = list(map(int, input().split(' ')))
n = l[0]
m = l[1]
s = input().split(' ')
t = input().split(' ')
q = int(input())
for i in range(q):
	y = int(input())
	if y % n == 0:
		sindex = n - 1
	if y % m == 0:
		tindex = m - 1
	sindex = y % n - 1
	tindex = y % m - 1
	name = s[sindex] + t[tindex]
	print(name)


(n, m) = input().split(' ')
n = int(n)
m = int(m)
s = input().split(' ')
t = input().split(' ')
q = int(input())
for w in range(q):
	y = int(input())
	a = y % n
	b = y % m
	if a == 0:
		a = n
	if b == 0:
		b = m
	a -= 1
	b -= 1
	print(s[a], t[b], sep='')


from math import *
(n, m) = map(int, input().split())
l = list(map(str, input().split()))
r = list(map(str, input().split()))
t = int(input())
for _ in range(t):
	a = int(input())
	k = a % n
	if k == 0:
		p = l[n - 1]
	else:
		p = l[k - 1]
	q = a % m
	if q == 0:
		p = p + r[m - 1]
	else:
		p = p + r[q - 1]
	print(p)


n = list(map(int, input().split(' ')))
s = list(input().split(' '))
t = list(input().split(' '))
c = int(input())
while c != 0:
	num = int(input())
	r1 = (num - 1) % n[0]
	r2 = (num - 1) % n[1]
	ans = s[r1] + t[r2]
	print(ans)
	c = c - 1


(n, m) = map(int, input().split())
a = input().split()
b = input().split()
q = int(input())
for i in range(q):
	y = int(input()) - 1
	f = a[y % n]
	l = b[y % m]
	print(f + l)


(n, m) = map(int, input().split())
l1 = list(map(str, input().split()))
l2 = list(map(str, input().split()))
for i in range(int(input())):
	num = int(input())
	print(l1[num % n - 1] + l2[num % m - 1])


(n, m) = map(int, input().split())
s1 = input().split()
s2 = input().split()
q = int(input())
for _ in range(q):
	x = int(input())
	ans = s1[(x - 1) % n] + s2[(x - 1) % m]
	print(ans)


(n, m) = map(int, input().split())
s = list(input().split())
t = list(input().split())
q = int(input())
output = []
for i in range(0, q):
	y = int(input())
	output.append(s[y % n - 1] + t[y % m - 1])
for j in output:
	print(j)


(n, m) = map(int, input().split())
s = list(map(str, input().split()))
t = list(map(str, input().split()))
test = int(input())
slength = len(s)
tlength = len(t)
for _ in range(test):
	i = int(input())
	print(s[slength - 1 if i % slength == 0 else i % slength - 1] + t[tlength - 1 if i % tlength == 0 else i % tlength - 1])


def main():
	(n, m) = [int(x) for x in input().split(' ')]
	sn = input().split(' ')
	tm = input().split(' ')
	q = int(input())
	for i in range(q):
		y = int(input()) - 1
		s_index = y % n
		t_index = y % m
		print(sn[s_index] + tm[t_index])
main()


(n, m) = map(int, input().split())
arr1 = list(input().split())
arr2 = list(input().split())
t = int(input())
for i in range(t):
	x = int(input())
	res = arr1[(x - 1) % n] + arr2[(x - 1) % m]
	print(res)


(x, y) = map(int, input().split())
s = []
add = ''
l1 = list(map(str, input().split()))
l2 = list(map(str, input().split()))
q = int(input())
for i in range(q):
	a = int(input())
	s.append(a)
for j in s:
	add = l1[(j - 1) % len(l1)] + l2[(j - 1) % len(l2)]
	print(add)


def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
(n, m) = map(int, input().split())
n_list = input().split()
m_list = input().split()
q = int(input())
g = gcd(n, m)
mcm = n * m // g
n_list = n_list * mcm
m_list = m_list * mcm
for i in range(q):
	a = int(input())
	x = mcm if a % mcm == 0 else a % mcm
	print('{}{}'.format(n_list[x - 1], m_list[x - 1]))


ints = list(map(int, input().split()))
(n, m) = (ints[0], ints[1])
s = input().split()
t = input().split()
q = int(input())
for qi in range(q):
	year = int(input())
	print(s[(year - 1) % n] + t[(year - 1) % m])


(n, m) = map(int, input().split())
s = list(map(str, input().split()))
t = list(map(str, input().split()))
s1 = len(s)
t1 = len(t)
a = int(input())
for i in range(a):
	y = int(input())
	print(s[(y - 1) % s1] + t[(y - 1) % t1])


(x, y) = input().split()
x = int(x)
y = int(y)
a = input().split()
b = input().split()
z = int(input())
c = list()
r = 0
while r < z:
	c.append(input())
	r = r + 1
for s in c:
	s = int(s) - 1
	l = s % x
	m = s % y
	print(a[l] + b[m])


(n, m) = map(int, input().split(' '))
sn = input().split(' ')
sm = input().split(' ')
q = int(input())
for k in range(q):
	y = int(input()) - 1
	print(sn[y % n] + sm[y % m])


(n, m) = map(int, input().split())
set1 = input().split()
set2 = input().split()
for i in range(int(input())):
	year = int(input()) - 1
	print(set1[year % n] + set2[year % m])


(a, b) = map(int, input().split())
c = input().split()
d = input().split()
for i in range(int(input())):
	m = int(input())
	print(c[m % a - 1] + d[m % b - 1])


(a, b) = map(int, input().split())
s1 = list(map(str, input().split()))
s2 = list(map(str, input().split()))
q = int(input())
for _ in range(q):
	n = int(input())
	if n <= a:
		r1 = n - 1
	elif n % a == 0:
		r1 = a - 1
	else:
		r1 = n % a - 1
	if n <= b:
		r2 = n - 1
	elif n % b == 0:
		r2 = b - 1
	else:
		r2 = n % b - 1
	print(s1[r1], s2[r2], sep='')


(z, x) = map(int, input().split())
a = input().split()
b = input().split()
n = int(input())
for i in range(n):
	m = int(input())
	q = m % z
	r = m % x
	print(a[q - 1], b[r - 1], sep='')


def newYear(nlis, mlis, num):
	if num < len(nlis) and num < len(mlis):
		return nlis[num - 1] + mlis[num - 1]
	return nlis[num % len(nlis) - 1] + mlis[num % len(mlis) - 1]
(n, m) = map(int, input().strip().split(' '))
nlis = list(input().strip().split(' '))
mlis = list(input().strip().split(' '))
q = int(input())
for i in range(q):
	num = int(input().strip())
	print(newYear(nlis, mlis, num))


(n, m) = [int(_) for _ in input().split()]
l1 = input().split()
l2 = input().split()
for __ in range(int(input())):
	y = int(input())
	print(l1[y % n - 1] + l2[y % m - 1])


(n, m) = map(int, input().split(' '))
s = input().split(' ')
t = input().split(' ')
q = int(input())
for i in range(q):
	y = int(input())
	first = y % n - 1
	second = y % m - 1
	answer = s[first] + t[second]
	print(answer)


import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
(n, m) = [int(item) for item in input().split()]
worda = [item for item in input().split()]
wordb = [item for item in input().split()]
alen = len(worda)
blen = len(wordb)
t = int(input())
for i in range(t):
	y = int(input()) - 1
	ans = worda[y % alen] + wordb[y % blen]
	print(ans)


(n, m) = [int(i) for i in input().split(' ')]
s = input().split(' ')
t = input().split(' ')
q = int(input())
for i in range(q):
	l = int(input())
	print(s[l % n - 1] + t[l % m - 1])


(n, m) = list(map(int, input().split()))
s = list(input().split())
t = list(input().split())
s.insert(0, None)
t.insert(0, None)
for _ in range(int(input())):
	year = int(input())
	if year % n == 0:
		a1 = n
	else:
		a1 = year % n
	if year % m == 0:
		a2 = m
	else:
		a2 = year % m
	print(s[a1] + t[a2])


(n, m) = input().split()
n = int(n)
m = int(m)
s = input().split()
t = input().split()
N = int(input())
for _ in range(N):
	num = int(input())
	if num % n == 0:
		a = s[-1]
	else:
		a = s[num % n - 1]
	if num % m == 0:
		b = t[-1]
	else:
		b = t[num % m - 1]
	ans = ''.join(a + b)
	print(ans)


from sys import stdin, stdout
from math import gcd
readline = stdin.readline
(m, n) = readline().split()
(m, n) = (int(m), int(n))
s = readline().split()
t = readline().split()
lcm = m * n // gcd(m, n)
zipped = zip(s * (lcm // m), t * (lcm // n))
lookup = ['%s%s' % (x[0], x[1]) for x in zipped]
q = int(readline())
output = ''
for i in range(q):
	query = int(readline())
	output += lookup[(query - 1) % lcm]
	if i != q - 1:
		output += '\n'
stdout.write(output)


(n, m) = [int(x) for x in input().split()]
L = [x for x in input().split()]
M = [x for x in input().split()]
q = int(input())
res = []
M = M * n
L = L * m
for i in range(q):
	y = int(input())
	y = y % (n * m)
	res.append(L[y - 1] + M[y - 1])
for k in res:
	print(k)


(n, m) = [int(el) for el in input().split()]
s = input().split()
t = input().split()
q = int(input())
for i in range(q):
	y = int(input())
	y -= 1
	a = y % n
	b = y % m
	print(s[a] + t[b])


p = []
q = []
d = []
n = input().split()
m = input().split()
k = input().split()
j = int(input())
p = k * len(m)
q = m * len(k)
for e in range(j):
	d.append(int(input()))
for i in range(len(d)):
	print(q[d[i] % (len(m) * len(k)) - 1] + p[d[i] % (len(m) * len(k)) - 1])


(a_length, b_length) = input().split()
a_length = int(a_length)
b_length = int(b_length)
a_words = input().split()
b_words = input().split()
years_length = int(input())
for i in range(years_length):
	year = int(input()) - 1
	a_word = a_words[year % a_length]
	b_word = b_words[year % b_length]
	print(a_word + b_word)


def solve(s, t, n, sn, tn):
	idx1 = n % sn
	idx2 = n % tn
	return s[idx1] + t[idx2]
(n, m) = map(int, input().split())
s = input().split()
t = input().split()
q = int(input())
sn = len(s)
tn = len(t)
for _ in range(q):
	n = int(input())
	print(solve(s, t, n - 1, sn, tn))


(n, m) = tuple(map(int, input().split()))
s = list(input().split())
t = list(input().split())
c = int(input())
for i in range(c):
	o = int(input())
	print(s[o % n - 1] + t[o % m - 1])


nm = input().split()
n = int(nm[0])
m = int(nm[1])
s = input().split()
t = input().split()
dictionary = {}
dictionary[1] = s[0] + t[0]
k = 0
l = 0
for i in range(1, 4 * (n * m)):
	k += 1
	k = k % n
	l += 1
	l = l % m
	dictionary[i + 1] = s[k] + t[l]
t = int(input())
for i in range(t):
	temp = int(input())
	if temp % (n * m) == 0:
		print(dictionary.get(n * m))
	else:
		print(dictionary.get(temp % (n * m)))


(N, M) = [int(x) for x in input().split()]
NS = [x for x in input().split()]
NSS = [NS[-1]] + NS[:-1]
MS = [x for x in input().split()]
MSS = [MS[-1]] + MS[:-1]
nb = int(input())
for _ in range(nb):
	curr = int(input())
	print(NSS[curr % N] + MSS[curr % M])


(n, m) = map(int, input().split())
tab = list(input().split())
sec = list(input().split())
for _ in range(int(input())):
	y = int(input())
	print(tab[y % n - 1] + sec[y % m - 1])


import sys

def fastio():
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

def debug(*var, sep=' ', end='\n'):
	print(*var, file=sys.stderr, end=end, sep=sep)
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
(n, m) = I()
s = input().split()
t = input().split()
(q,) = I()
while q:
	q -= 1
	(y,) = I()
	y -= 1
	print(s[y % n] + t[y % m])


(n, m) = list(map(int, input().split()))
first = input().split()
second = input().split()
q = int(input())
for _ in range(q):
	query = int(input())
	print(first[query % n - 1] + second[query % m - 1])


def main():
	import sys
	input = sys.stdin.readline
	(N, M) = map(int, input().split())
	S = list(input().split())
	T = list(input().split())
	Q = int(input())
	for _ in range(Q):
		y = int(input())
		y -= 1
		print(S[y % N] + T[y % M])
main()


nu = input().split()
a = int(nu[0])
b = int(nu[1])
l1 = list(input().split(' '))
l2 = list(input().split(' '))
t = int(input())
while t > 0:
	y = int(input()) - 1
	c = y % a
	d = y % b
	print(l1[c], end='')
	print(l2[d])
	t -= 1


(a, b) = map(int, input().split())
(s, t) = (input().split(), input().split())
for i in range(int(input())):
	x = int(input())
	print(s[(x - 1) % a] + t[(x - 1) % b])


(n, m) = list(map(int, input().split()))
s = list(map(str, input().split()))
t = list(map(str, input().split()))
q = int(input())
y = list()
for i in range(q):
	temp = int(input())
	y.append(temp)
for i in range(q):
	tempi = int(y[i] % n)
	tempj = int(y[i] % m)
	print(s[tempi - 1] + t[tempj - 1])


(a, b) = map(int, input().split(' '))
x = list(map(str, input().split(' ')))
y = list(map(str, input().split(' ')))
q = int(input())
res = []
for _ in range(q):
	queries = int(input())
	a1 = queries % a - 1
	b1 = queries % b - 1
	res.append(x[a1] + y[b1])
for i in res:
	print(i)


mn = [int(x) for x in input().split(' ')]
m = mn[0]
n = mn[1]
s = input().split(' ')
t = input().split(' ')
s_len = len(s)
t_len = len(t)
size = int(input())
for _ in range(size):
	year = int(input())
	out = ''
	if year % s_len == 0:
		out += s[s_len - 1]
	else:
		out += s[year % s_len - 1]
	if year % t_len == 0:
		out += t[t_len - 1]
	else:
		out += t[year % t_len - 1]
	print(out)


(n, m) = list(map(int, input().split()))
l1 = list(input().split())
l2 = list(input().split())
t = int(input())
for _ in range(t):
	k = int(input())
	a = l1[(k - 1) % n] + l2[(k - 1) % m]
	print(a)


def findYear():
	for _ in range(t):
		year = int(input())
		yield (lst1[(year - 1) % n] + lst2[(year - 1) % m])
(n, m) = map(int, input().split())
lst1 = [ele for ele in input().split()]
lst2 = [ele for ele in input().split()]
t = int(input())
ans = findYear()
print(*ans, sep='\n')


(n, m) = map(int, input().split())
s1 = input().split()
s2 = input().split()
q = int(input())
for _ in range(q):
	year = int(input())
	print(s1[(year - 1) % n] + s2[(year - 1) % m])


(n, m) = map(int, input().split())
s1 = list(map(str, input().split()))
s2 = list(map(str, input().split()))
a = []
i = 0
j = 0
while 1:
	a.append(s1[i] + s2[j])
	i = (i + 1) % n
	j = (j + 1) % m
	if i == 0 and j == 0:
		break
for _ in range(int(input())):
	q = int(input())
	print(a[(q - 1) % len(a)])


numberl = []
(r, g) = map(int, input().split())
starr1 = list(map(str, input().split()))
starr2 = list(map(str, input().split()))
num = int(input())
for i in range(num):
	ele = int(input())
	numberl.append(ele)
for i in range(num):
	x = numberl[i] % r
	y = numberl[i] % g
	if x == 0:
		x = r
	if y == 0:
		y = g
	print(starr1[x - 1] + starr2[y - 1])


(n, m) = map(int, input().split())
s = list(input().split())
t = list(input().split())

def convert_to_bounds(val, l):
	if val >= l:
		g = int(val / l)
		val -= g * l
	return int(val)
for i in range(int(input())):
	z = int(input())
	a = convert_to_bounds(z - 1, n)
	b = convert_to_bounds(z - 1, m)
	(x, y) = (s[a], t[b])
	print(x + y)


(len1, len2) = map(int, input().split(' '))
first = input().split(' ')
second = input().split(' ')
hm = int(input())
for i in range(hm):
	year = int(input())
	print(first[year % len1 - 1] + second[year % len2 - 1])


def main():
	import sys
	(n, m) = map(int, input().split())
	a = list(map(str, input().split()))
	b = list(map(str, input().split()))
	res = [(0, 0)]
	f = 1
	s = 1
	while (f % n, s % m) != (0, 0):
		res.append((f % n, s % m))
		f += 1
		s += 1
	q = int(input())
	for i in range(q):
		y = int(input())
		y -= 1
		x = res[y % len(res)]
		print(a[x[0]] + b[x[1]])
main()


input()
n = input().split()
m = input().split()
z = int(input())
for a in range(z):
	year = int(input())
	res = ''
	if year % len(n) == 0:
		res += n[-1]
	else:
		res += n[year % len(n) - 1]
	if year % len(m) == 0:
		res += m[-1]
	else:
		res += m[year % len(m) - 1]
	print(res)


(l_p, l_s) = map(int, input().split(' '))
pc = input().split(' ')
sc = input().split(' ')
rango = int(input())
for i in range(rango):
	num = int(input())
	print(pc[num % l_p - 1] + sc[num % l_s - 1])


import sys
input()
s = [str(s) for s in input().split()]
t = [str(t) for t in input().split()]
n = int(input())
m = []
for i in range(n):
	m.append(int(input()) - 1)
for j in m:
	print(s[j % len(s)] + t[j % len(t)])


(n, m) = map(int, input().split())
s = input().split()
t = input().split()
q = int(input())
for _ in range(q):
	y = int(input())
	name = s[y % n - 1] + t[y % m - 1]
	print(name)


(a, b) = list(map(int, input().split()))
s = list(input().split())
t = list(input().split())
for i in range(int(input())):
	p = ''
	q = int(input())
	p += s[q % a - 1] + t[q % b - 1]
	print(p)


import sys
import math
from collections import defaultdict, Counter
input = sys.stdin.readline

def print(x):
	sys.stdout.write(str(x) + '\n')
(n, m) = map(int, input().split())
n1 = input().split()
m1 = input().split()
q = int(input())
for i in range(q):
	y = int(input())
	y -= 1
	ans = n1[y % n] + m1[y % m]
	print(ans)


(n, m) = map(int, input().split())
s = input().split()
t = input().split()
l = int(input())
for i in range(l):
	j = int(input())
	print(s[(j % (n * m) % n - 1) % n] + t[(j % (n * m) % m - 1) % m])


(a, b) = [int(i) for i in input().split()]
set_a = input().split()
set_b = input().split()
q = int(input())
for _ in range(q):
	year = int(input())
	string_a = set_a[year % a - 1]
	string_b = set_b[year % b - 1]
	print(string_a + string_b)


import sys
from functools import reduce
from collections import Counter
import time
import datetime
import math

def ip():
	return int(sys.stdin.readline())

def sip():
	return input()

def mip():
	return map(int, sys.stdin.readline().split())

def mips():
	return map(str, sys.stdin.readline().split())

def lip():
	return list(map(int, sys.stdin.readline().split()))

def slip():
	return list(map(str, sys.stdin.readline().split()))

def matip(n, m):
	lst = []
	for i in range(n):
		arr = lip()
		lst.insert(i, arr)
	return lst

def factors(n):
	return list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def minJumps(arr, n):
	jumps = [0 for i in range(n)]
	if n == 0 or arr[0] == 0:
		return float('inf')
	jumps[0] = 0
	for i in range(1, n):
		jumps[i] = float('inf')
		for j in range(i):
			if i <= j + arr[j] and jumps[j] != float('inf'):
				jumps[i] = min(jumps[i], jumps[j] + 1)
				break
	return jumps[n - 1]

def dic(arr):
	return Counter(arr)

def check_prime(n):
	if n < 2:
		return False
	for i in range(2, int(n ** 0.5) + 1, 2):
		if n % i == 0:
			return False
	return True
(n, m) = mip()
arr1 = slip()
arr2 = slip()
q = ip()
while q:
	q -= 1
	num = ip()
	a = num % n
	b = num % m
	print(arr1[a - 1] + arr2[b - 1])


(n, m) = map(int, input().split())
a = list(map(str, input().split()))
b = list(map(str, input().split()))
s = int(input())
while s:
	c = int(input())
	print(a[c % n - 1] + b[c % m - 1])
	s -= 1


(n, m) = map(int, input().split())
s = list(input().split())
t = list(input().split())
c = int(input())
for _ in range(c):
	v = int(input())
	print(s[(v - 1) % n] + t[(v - 1) % m])


(n, m) = map(int, input().split())
s = [str(i) for i in input().split()][:n]
t = [str(i) for i in input().split()][:m]
for _ in range(int(input())):
	y = int(input()) - 1
	print(s[y % len(s)] + t[y % len(t)])


def get_index(x, y, z):
	if x % y == 0:
		return z
	else:
		return int(x % y) - 1
(N, M) = map(int, input().split())
l1 = list(map(str, input().split()))
l2 = list(map(str, input().split()))
Yr = int(input())
while Yr > 0:
	y = int(input())
	print(l1[get_index(y, len(l1), len(l1) - 1)] + l2[get_index(y, len(l2), len(l2) - 1)])
	Yr -= 1


(n, m) = map(int, input().split())
s = list(input().split(' '))[:n]
t = list(input().split(' '))[:m]
q = int(input())
for i in range(q):
	year = int(input())
	ins = year % n
	intl = year % m
	if ins != 0 and intl != 0:
		print(s[ins - 1] + t[intl - 1])
	elif ins == 0 and intl != 0:
		print(s[n - 1] + t[intl - 1])
	elif ins != 0 and intl == 0:
		print(s[ins - 1] + t[m - 1])
	elif ins == 0 and intl == 0:
		print(s[n - 1] + t[m - 1])


(n, m) = input().split(' ')
n = int(n)
m = int(m)
s = input()
s1 = input()
s2 = list(map(str, s.split(' ')))
s3 = list(map(str, s1.split(' ')))
l = []
l.append('########')
i = 0
if len(s2) == len(s3):
	p = len(s)
	while p > 0:
		for i in range(0, len(s2)):
			s4 = ''
			s4 = s2[i] + s3[i]
			l.append(s4)
		p = p - 1
else:
	p = len(s2) * len(s3)
	i = 0
	j = 0
	while p > 0:
		if i >= len(s2):
			i = 0
		if j >= len(s3):
			j = 0
		s4 = ''
		s4 = s2[i] + s3[j]
		l.append(s4)
		i += 1
		j += 1
		p = p - 1
q = int(input())
while q > 0:
	n1 = int(input())
	p = n1 % (len(s2) * len(s3))
	if p == 0:
		print(l[len(s2) * len(s3)])
	else:
		print(l[p])
	q = q - 1


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
A = input().rstrip().split()
B = input().rstrip().split()
for _ in range(int(input())):
	t = int(input())
	print(A[t % n - 1] + B[t % m - 1])


(n, m) = map(int, input().split())
arr1 = list(map(str, input().split()))
arr2 = list(map(str, input().split()))
q = int(input())
while q:
	qs = int(input())
	print(arr1[qs % n - 1], end='')
	print(arr2[qs % m - 1])
	q = q - 1


(f, s) = map(int, input().split())
first = list(map(str, input().split()))
second = list(map(str, input().split()))

def find(year):
	index1 = year % f
	index2 = year % s
	return first[index1 - 1] + second[index2 - 1]
for _ in range(int(input())):
	temp = int(input())
	print(find(temp))


(n, m) = list(map(int, input().split()))
s = list(map(str, input().split()))
t = list(map(str, input().split()))
q = int(input())
years = []
for i in range(q):
	year = int(input())
	years.append(year)
korean_years = []
for j in years:
	if len(s) > j and len(t) > j:
		korean_year = s[j - 1] + t[j - 1]
		korean_years.append(korean_year)
	else:
		korean_year = s[j % len(s) - 1] + t[j % len(t) - 1]
		korean_years.append(korean_year)
for korean_year in korean_years:
	print(korean_year)


(n, m) = map(int, input().split())
s = list(map(str, input().split()))
t = list(map(str, input().split()))
q = int(input())
year = []
for i in range(q):
	year.append(int(input()))
for i in year:
	(x, y) = (0, 0)
	x = i % n - 1
	y = i % m - 1
	print(s[x], end='')
	print(t[y])


import sys
[n, m] = list(map(int, sys.stdin.readline().strip().split(' ')))
s = list(sys.stdin.readline().strip().split(' '))
t = list(sys.stdin.readline().strip().split(' '))
q = int(sys.stdin.readline().strip())
for i in range(q):
	year = int(sys.stdin.readline())
	print(s[(year - 1) % n] + t[(year - 1) % m])


(x, y) = map(int, input().split())
a = list(map(str, input().split()))
b = list(map(str, input().split()))
t = int(input())
while t:
	t -= 1
	n = int(input())
	n -= 1
	print('%s%s' % (a[n % x], b[n % y]))


(n, m) = map(int, input().split())
n_string = input().split()
m_string = input().split()
queries = int(input())
while queries:
	year = int(input())
	m_index = (-1 + year) % m
	n_index = (-1 + year) % n
	print(n_string[n_index] + m_string[m_index])
	queries -= 1


(n, m) = map(int, input().split())
s = input().split()
t = input().split()
q = int(input())
for i in range(q):
	w = int(input())
	x = w // n
	x = x * n
	o = w - x
	e = s[o - 1]
	y = w // m
	y = y * m
	o = w - y
	r = t[o - 1]
	print(e + r)


(n, k) = map(int, input().split())
ns = input().split()
ks = input().split()
for _ in range(int(input())):
	v = int(input())
	print(ns[v % n - 1] + ks[v % k - 1])


(n, m) = input().split()
n = int(n)
m = int(m)
l1 = list(input().split())
l2 = list(input().split())

def program():
	k = int(input())
	print(l1[k % n - 1] + l2[k % m - 1])
t = int(input())
for i in range(t):
	program()


x = input().split(' ')
n = int(x[0])
m = int(x[1])
litn = []
litm = []
s = input()
litn = s.split(' ')
s = input()
litm = s.split(' ')
q = int(input())
len1 = len(litn)
len2 = len(litm)
for i in range(q):
	x12 = int(input())
	ans = litn[x12 % len1 - 1] + litm[x12 % len2 - 1]
	print(ans)


inp1 = input().split()
n = int(inp1[0])
m = int(inp1[1])
inp2 = input().split()
inp3 = input().split()
t = int(input())
while t > 0:
	t -= 1
	year = int(input())
	str1 = inp2[year % n - 1]
	str2 = inp3[year % m - 1]
	print(str1 + str2)


unsplitN = input().split(' ')
n = int(unsplitN[0])
m = int(unsplitN[1])
s = []
t = []
a = 0
b = 0
unsplitS = input()
unsplitT = input()
s = unsplitS.split(' ')
t = unsplitT.split(' ')
q = int(input())
for i in range(q):
	y = int(input())
	y = y - 1
	if y >= n:
		a = y % n
	else:
		a = y
	if y >= m:
		b = y % m
	else:
		b = y
	print(s[a] + t[b])


(a, b) = map(int, input().split())
x = list(input().split())
y = list(input().split())
for _ in range(int(input())):
	k = int(input()) - 1
	print(x[k % a] + y[k % b])


empty = input('')
n = input().split()
m = input().split()
queries = int(input())
for i in range(queries):
	q = int(input(''))
	print(n[q % len(n) - 1] + m[q % len(m) - 1])


input()
(a, b) = (input().split(), input().split())
for _ in range(int(input())):
	t = int(input())
	print(a[t % len(a) - 1] + b[t % len(b) - 1])


(n, m) = [*map(int, input().split())]
l = input().split()
k = input().split()
for _ in range(int(input())):
	p = int(input())
	ans = p % n
	an = p % m
	print(l[ans - 1] + k[an - 1])


(n, m) = map(int, input().split())
ns = input().split()
ms = input().split()
q = int(input())
for i in range(1, q + 1):
	j = int(input())
	msc = j % m
	nsc = j % n
	print(ns[nsc - 1] + ms[msc - 1])


(a, b) = map(int, input().split())
lisOne = list(map(str, input().split()))
lisTwo = list(map(str, input().split()))
f = int(input())
for i in range(f):
	c = int(input())
	print(lisOne[(c - 1) % a] + lisTwo[(c - 1) % b])


ls = list(map(int, input().split()))
n = ls[0]
m = ls[1]
ls1 = list(map(str, input().split()))
ls2 = list(map(str, input().split()))
q = int(input())
ls3 = []
for i in range(q):
	val = int(input())
	ls3.append(val)
for i in range(len(ls3)):
	idx1 = ls3[i] % n - 1
	if idx1 == -1:
		idx1 = n - 1
	idx2 = ls3[i] % m - 1
	if idx2 == -1:
		idx2 = m - 1
	print(ls1[idx1] + ls2[idx2])


from sys import stdin

def main():
	input = lambda : stdin.readline()[:-1]
	(N, M) = map(int, input().split())
	S = input().split()
	T = input().split()
	Q = int(input())
	for _ in [0] * Q:
		Y = int(input())
		(n, m) = (Y % N - 1, Y % M - 1)
		print(S[n] + T[m])
main()


(n, m) = [int(x) for x in input().split(' ')]
ns = [str(x) for x in input().split(' ')]
ms = [str(x) for x in input().split(' ')]
q = int(input())
for i in range(q):
	c = int(input())
	print(ns[c % n - 1] + ms[c % m - 1])


temp = input().split()
for (pos, x) in enumerate(temp):
	temp[pos] = int(x)
line1 = input().split()
line2 = input().split()
arv = int(input())
data = []
for x in range(arv):
	data.append(int(input()))
for x in data:
	name = ''
	if x - 1 < temp[0]:
		name = name + line1[x - 1]
	else:
		pos = (x - 1) % temp[0]
		name = name + line1[pos]
	if x - 1 < temp[1]:
		name = name + line2[x - 1]
	else:
		pos = (x - 1) % temp[1]
		name = name + line2[pos]
	print(name)


import sys
input_string = []
for line in sys.stdin:
	input_string.append(line[:-1])
(n, m) = input_string[0].split(' ')
n_list = input_string[1].split(' ')
m_list = input_string[2].split(' ')
p = input_string[3]
problems = input_string[4:]
for problem in problems:
	print(n_list[(int(problem) - 1) % int(n)] + m_list[(int(problem) - 1) % int(m)])


(n, m) = map(int, input().split())
l1 = list(map(str, input().split()))
l2 = list(map(str, input().split()))
for _ in range(int(input())):
	p = int(input())
	x = l1[p % n - 1]
	y = l2[p % m - 1]
	print(x, end='')
	print(y)


(n, m) = map(int, input().split())
L1 = list(map(str, input().split()))
L2 = list(map(str, input().split()))
L = []
for i in range(1, m * n + 1):
	s = L1[i % n - 1] + L2[i % m - 1]
	L.append(s)
q = int(input())
for i in range(q):
	q1 = int(input())
	print(L[q1 % len(L) - 1])


from itertools import cycle
(n, m) = list(map(int, input().split()))
stringList1 = list(map(str, input().split()))
stringList2 = list(map(str, input().split()))
queries = int(input())
for q in range(queries):
	idx = int(input())
	idx = idx - 1
	ans = stringList1[idx % n] + stringList2[idx % m]
	print(ans)


(n, m) = map(int, input().split())
nl = list(map(str, input().split()))
ml = list(map(str, input().split()))
for _ in range(int(input())):
	p = int(input())
	print(nl[p % n - 1] + ml[p % m - 1])


def hcf(x, y):
	while y != 0:
		(x, y) = (y, x % y)
	return x

def lcm(x, y):
	return x * y // hcf(x, y)
(n, m) = map(int, input().split())
s = list(input().split())
t = list(input().split())
q = int(input())
arr = []
for _ in range(q):
	arr.append(int(input()))
if n > m:
	num = lcm(m, n)
else:
	num = lcm(n, m)
brr = []
for i in range(num):
	brr.append(s[i % n] + t[i % m])
for i in arr:
	print(brr[i % num - 1])


(a, b) = map(int, input().split())
m = input()
m = m.split()
n = input()
n = n.split()
N = int(input())
for i in range(N):
	temp = int(input())
	x = temp % a
	y = temp % b
	print(m[x - 1] + n[y - 1])


def get_year(n, t, list_n, list_t, year):
	result = ''
	if year > n:
		remainder = year % n
		result = result + list_n[remainder - 1]
	else:
		result = result + list_n[year - 1]
	if year > t:
		remainder = year % t
		result = result + list_t[remainder - 1]
	else:
		result = result + list_t[year - 1]
	return result
(n, t) = map(int, input().split(' '))
list_n = [x for x in input().split(' ')]
list_t = [x for x in input().split(' ')]
queries = int(input())
for query in range(queries):
	year = int(input())
	print(get_year(n, t, list_n, list_t, year))


(n, m) = list(map(int, input().split()))
s = input().split()
t = input().split()
y = int(input())
for i in range(y):
	x = int(input())
	mn = x % n
	mm = x % m
	a = s[n - 1 if mn == 0 else mn - 1]
	b = t[m - 1 if mm == 0 else mm - 1]
	print(a + b)


nums = input().split()
n = nums[0]
m = nums[1]
s = input().split()
t = input().split()
q = int(input())
for i in range(q):
	y = int(input())
	s_str = y % len(s) - 1
	t_str = y % len(t) - 1
	print(s[s_str] + t[t_str])


(m, n) = map(int, input().split())
mm = list(input().split(' '))
nn = list(input().split(' '))
for _ in range(int(input())):
	k = int(input())
	mmm = k % m
	nnn = k % n
	mmm = (mmm + m - 1) % m
	nnn = (nnn + n - 1) % n
	ans = mm[mmm] + nn[nnn]
	print(ans)


input()
a = input().split()
b = input().split()
q = int(input())
for _ in range(q):
	n = int(input()) - 1
	print(a[n % len(a)] + b[n % len(b)])


from sys import stdin
input = stdin.readline
(n, m) = list(map(int, input().split()))
a = list(input().split())
b = list(input().split())
t = int(input())
for _ in range(t):
	year = int(input())
	print(a[(year - 1) % n] + b[(year - 1) % m])


import sys
import math
import heapq
import bisect
import re
from collections import deque
sys.setrecursionlimit(1000000000)

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def finput():
	return float(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())

def modst(w, s):
	res = 1
	while s:
		if s % 2:
			res *= w
		w *= w
		s //= 2
	return res

def error(n):
	print('YES')
	exit(n)

def main():
	(n, m) = rinput()
	w = tinput()
	e = tinput()
	for i in range(iinput()):
		q = iinput()
		print(w[(q - 1) % n] + e[(q - 1) % m])
for i in range(1):
	main()


(n, m) = map(int, input().split())
a1 = input()
b1 = input()
q = int(input())
a = a1.split()
b = b1.split()
p = []
for _ in range(q):
	q1 = int(input())
	for i in range(n * m):
		p.append(a[i % n] + b[i % m])
	print(p[(q1 - 1) % len(p)])


a = input().split()
b = input().split()
c = input().split()
d = int(input())
e = 0
for i in range(d):
	e = int(input())
	print(b[(e - 1) % int(a[0])] + c[(e - 1) % int(a[1])])


(n, m) = map(int, input().split())
n_lst = tuple(input().split())
m_lst = tuple(input().split())
num = int(input())
s = 0
t = 0
for _ in range(num):
	year = int(input())
	if year > n:
		s = year % n
	else:
		s = year
	if year > m:
		t = year % m
	else:
		t = year
	print(n_lst[s - 1] + m_lst[t - 1])


def main():
	(n, m) = list(map(int, input().split()))
	a = list(map(str, input().split()))
	b = list(map(str, input().split()))
	for _ in range(int(input())):
		y = int(input())
		y -= 1
		print(a[y % n] + b[y % m])
main()


from collections import deque
import itertools
import operator
import queue
import time
import math
import sys
import os
(n, m) = map(int, input().split())
s = list(map(str, input().split()))
t = list(map(str, input().split()))
q = int(input())
for i in range(q):
	h = int(input())
	print(s[(h - 1) % n] + t[(h - 1) % m])


(n, m) = map(int, input().split())
a = list(input().split())
b = list(input().split())
q = int(input())
for i in range(q):
	w = int(input()) - 1
	print(a[w % n] + b[w % m])


(a, b) = map(int, input().split())
p = list(map(str, input().split()))
q = list(map(str, input().split()))
for _ in range(int(input())):
	x = int(input())
	print(p[x % a - 1] + q[x % b - 1])


a = list(map(int, input().split()))
n = a[0]
m = a[1]
c = list(input().split())
d = list(input().split())
k = int(input())
for i in range(k):
	t = int(input())
	print(c[t % n - 1] + d[t % m - 1])


import sys
(n, m) = map(int, input().split())
s = input()
s = s.split()
t = input()
t = t.split()
q = int(input())
data = []
while q:
	x = int(input()) - 1
	data.append(s[x % n] + t[x % m])
	q -= 1
for i in data:
	print(i)


(n, m) = map(int, input().split(' '))
ns = input().split(' ')
ms = input().split(' ')
q = int(input())
for i in range(q):
	y = int(input())
	print(ns[(y - 1) % n] + ms[(y - 1) % m])


(a, b) = map(int, input().split())
e = []
x = list(map(str, input().split()))
y = list(map(str, input().split()))
k = int(input())
for i in range(k):
	s = int(input())
	e.append(x[(s - 1) % a] + y[(s - 1) % b])
for i in range(k):
	print(e[i])


(n, m) = [int(i) for i in input().split()]
a = [str(i) for i in input().split()]
b = [str(i) for i in input().split()]
kl = int(input())
for l in range(kl):
	k = int(input())
	k1 = k % n
	k2 = k % m
	print(a[k1 - 1] + b[k2 - 1])


def name(s, t, ql):
	for i in ql:
		sWord = i % len(s) - 1
		tWord = i % len(t) - 1
		print(s[sWord] + t[tWord])
input()
s = input().rstrip().split()
t = input().rstrip().split()
count = int(input())
ql = []
for _ in range(0, count):
	ql.append(int(input()))
name(s, t, ql)


(n, m) = map(int, input().split())
one = list(map(str, input().split()))
two = list(map(str, input().split()))
x = int(input())
year = list()
for j in range(x):
	year.append(int(input()))
for j in range(x):
	a = year[j] % n
	b = year[j] % m
	print(one[a - 1] + two[b - 1])


(n, k) = map(int, input().split())
l = list(input().split())
m = list(input().split())
for _ in range(int(input())):
	a = int(input())
	x = a % n
	y = a % k
	print(l[x - 1], end='')
	print(m[y - 1], end='')
	print()


x = list(map(int, input().split(' ')))
s = input().split(' ')
t = input().split(' ')
times = int(input())
for q in range(0, times):
	xx = int(input())
	smod = xx % x[0]
	tmod = xx % x[1]
	print(s[smod - 1] + t[tmod - 1])


(n, m) = map(int, input().split())
nm = n * m
si = input().split()
ti = input().split()
q = int(input())
for i in range(q):
	y = int(input())
	temp = y % nm - 1
	print(si[temp % n] + ti[temp % m])


(n, m) = [int(i) for i in input().split()]
a = input().split()
b = input().split()
q = int(input())
for _ in range(q):
	num = int(input())
	n1 = num % n - 1
	n2 = num % m - 1
	print('{}{}'.format(a[n1], b[n2]))


(n, m) = map(int, input().split())
a = list(input().split())
b = list(input().split())
t = int(input())
while t > 0:
	t -= 1
	x = int(input())
	if x == n:
		i = n
	else:
		i = x % n
	if x == m:
		j = m
	else:
		j = x % m
	z = a[i - 1] + b[j - 1]
	print(z)


import sys
(n, m) = map(int, input().strip().split())
lst_a = list(input().strip().split(' '))
lst_b = list(input().strip().split(' '))
for _ in range(int(input())):
	a = int(input()) - 1
	sys.stdout.write(lst_a[a % len(lst_a)] + lst_b[a % len(lst_b)] + '\n')


def program(year1, year2):
	if year1 >= length_first:
		year1 = year1 % length_first
	if year2 >= length_sec:
		year2 = year2 % length_sec
	w1 = first[year1]
	w2 = sec[year2]
	return w1 + w2
a = list(map(int, input().strip().split()))
length_first = a[0]
length_sec = a[1]
first = list(map(str, input().strip().split()))
sec = list(map(str, input().strip().split()))
case = int(input())
for i in range(case):
	year1 = int(input()) - 1
	year2 = year1
	print(program(year1, year2))


(n, m) = map(int, input().split())
arr1 = [str(i) for i in input().split()]
arr2 = [str(i) for i in input().split()]
q = int(input())
for i in range(q):
	y = int(input())
	a = y % n
	b = y % m
	print(arr1[a - 1] + arr2[b - 1])


(n, m) = [int(j) for j in input().split()]
a = [i for i in input().split()]
b = [i for i in input().split()]
la = len(a)
lb = len(b)
for i in range(int(input())):
	k = int(input())
	print(a[(k - 1) % la] + b[(k - 1) % lb])


from array import array
from sys import stdin
import bisect
from itertools import *

def scan_gen():
	for line in stdin:
		yield from iter(line.split())
scan = scan_gen()

def nint():
	return int(next(scan))

def nintk(k):
	return tuple((nint() for _ in range(k)))

def nfloat():
	return float(next(scan))

def intar_init(size):
	return array('i', [0]) * size

def intar(size=None):
	if size == None:
		size = nint()
	arr = intar_init(size)
	for x in range(size):
		arr[x] = nint()
	return arr

def solve():
	(n, m) = nintk(2)
	S = []
	for _ in range(n):
		S.append(next(scan))
	S2 = []
	for _ in range(m):
		S2.append(next(scan))
	q = nint()
	Q = intar(q)
	for x in Q:
		x -= 1
		print(S[x % n] + S2[x % m])
solve()


(n, m) = map(int, input().split(' '))
s = list(input().split(' '))
t = list(input().split(' '))
q = int(input())
for _ in range(q):
	ans = []
	num = int(input())
	rem_s = num % n
	rem_t = num % m
	if not rem_s:
		ans.append(s[-1])
	else:
		ans.append(s[rem_s - 1])
	if not rem_t:
		ans.append(t[-1])
	else:
		ans.append(t[rem_t - 1])
	print(''.join(ans))


(n, m) = map(int, input().split())
L1 = list(input().split())
L2 = list(input().split())
q = int(input())
i = 0
j = 0
while q > 0:
	y = int(input())
	i = (y - 1) % n
	j = (y - 1) % m
	print(L1[i] + L2[j])
	q = q - 1


(n, m) = map(int, input().split(' '))
s = input().split(' ')
t = input().split(' ')
q = int(input())
for i in range(q):
	year = int(input())
	year_name = s[year % n - 1] + t[year % m - 1]
	print(year_name)


X = list(map(int, input().split()))
First = input().split()
Second = input().split()
for i in range(int(input())):
	N = int(input())
	print(First[N % X[0] - 1] + Second[N % X[1] - 1])


(n, m) = map(int, input().split())
a = input().split(' ')
b = input().split(' ')
c = int(input())
for i in range(c):
	z = int(input())
	e = z % n
	f = z % m
	if e == 0:
		e = n
	if f == 0:
		f = m
	print(a[e - 1] + b[f - 1])


(a, b) = input().split(' ')
lst1 = input()
lst2 = lst1.split(' ')
lst3 = input()
lst4 = lst3.split(' ')
c = int(input())
lst5 = []
for i in range(c):
	d = int(input()) - 1
	lst5.append(lst2[d % int(a)] + lst4[d % int(b)])
for j in range(len(lst5)):
	print(lst5[j])


from sys import stdin, stdout
inp = stdin.readline
say = stdout.write
(n, m) = [int(i) for i in inp().strip().split()]
ns = inp().strip().split()
nl = len(ns)
ms = inp().strip().split()
ml = len(ms)
q = int(inp().strip())
for _ in range(q):
	x = int(inp().strip())
	c1 = x
	c2 = x
	if nl < x:
		c1 = x % nl
	if ml < x:
		c2 = x % ml
	ss = ns[c1 - 1] + ms[c2 - 1]
	say('%s\n' % ss)


(a, b) = input().split()
a = int(a)
b = int(b)
s = input()
t = input()
slist = s.split()
tlist = t.split()
finalR = []
query = int(input())
no = query
while no > 0 and no <= 2020:
	i = int(input())
	i -= 1
	finalR.append(slist[i % a] + tlist[i % b])
	no = no - 1
for i in range(len(finalR)):
	print(finalR[i])


import sys
input = sys.stdin.readline
(n, m) = [int(x) for x in input().strip().split()]
s = input().strip().split()
t = input().strip().split()
len_s = len(s)
len_t = len(t)
q = int(input())
for _ in range(q):
	y = int(input())
	print(s[(y - 1) % len_s] + t[(y - 1) % len_t])


data = input()
(n, m) = data.split()
n = int(n)
m = int(m)
data = input()
ar1 = data.split()
data = input()
ar2 = data.split()
q = input()
q = int(q)
ar = []
for i in range(q):
	ar.append(input())
ar = list(map(int, ar))
for line in ar:
	i = line % n - 1
	j = line % m - 1
	print(ar1[i] + ar2[j])


(n, m) = map(int, input().split())
s = input().split()
s1 = input().split()
t = int(input())
for _ in range(t):
	p = int(input())
	print(s[(p - 1) % n] + s1[(p - 1) % m])


nm = input().split(' ')
nm[0] = int(nm[0])
nm[1] = int(nm[1])
a = input().split(' ')
b = input().split(' ')
query = int(input())
i = 0
while i < query:
	yearno = int(input())
	p = yearno % nm[0] - 1
	q = yearno % nm[1] - 1
	if p == -1:
		p = nm[0] - 1
	if q == -1:
		q = nm[1] - 1
	yearname = a[p] + b[q]
	print(yearname)
	i += 1


def solve(year, s, t):
	s_length = len(s)
	t_length = len(t)
	answer = ''
	answer += s[(year - 1) % s_length]
	answer += t[(year - 1) % t_length]
	return answer

def main():
	(n, m) = map(int, input().split())
	s_lst = list(input().split())
	t_lst = list(input().split())
	q = int(input())
	for i in range(q):
		year = int(input())
		print(solve(year, s_lst, t_lst))
main()


(n, m) = map(int, input().split())
s = input().split(' ')
t = input().split(' ')
rng = int(input())
names = []
for i in range(rng):
	str = ''
	year = int(input())
	if year <= n:
		str += s[year - 1]
	else:
		str += s[(year - 1) % n]
	if year <= m:
		str += t[year - 1]
	else:
		str += t[(year - 1) % m]
	names.append(str)
print(*names, sep='\n')


(n, m) = input().split()
(n, m) = (int(n), int(m))
s = input().split()
t = input().split()
q = int(input())
for i in range(q):
	y = int(input())
	print(s[y % n - 1], end='')
	print(t[y % m - 1])


from sys import stdin
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin

def ii():
	return int(stdin.readline())

def fi():
	return float(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def fmi():
	return map(float, stdin.readline().split())

def li():
	return list(mi())

def lsi():
	x = list(stdin.readline())
	x.pop()
	return x

def si():
	return stdin.readline()

def sieve(x):
	a = [True] * (x + 1)
	sq = floor(sqrt(x))
	for i in range(3, sq + 1, 2):
		if a[i]:
			for j in range(i * i, x + 1, i):
				a[j] = False
	if x > 1:
		p = [2]
	else:
		p = []
	for i in range(3, x + 1, 2):
		if a[i]:
			p.append(i)
	return p
(n, m) = mi()
a = list(input().split())
b = list(input().split())
p = [a[-1]] + a[:-1]
q = [b[-1]] + b[:-1]
for _ in range(ii()):
	x = ii()
	print(p[x % n] + q[x % m])


(n, m) = list(map(int, input().strip().split()))
arr_n = list(input().strip().split())
arr_m = list(input().strip().split())
t = int(input().strip())
for _ in range(t):
	y = int(input().strip())
	ans = arr_n[(y - 1) % n] + arr_m[(y - 1) % m]
	print(ans)


(n, m) = map(int, input().split())
s = list(map(str, input().split()))
t = list(map(str, input().split()))
for _ in range(int(input())):
	y = int(input())
	if y > n:
		a1 = y % n
	else:
		a1 = y
	if y > m:
		a2 = y % m
	else:
		a2 = y
	print(s[a1 - 1] + t[a2 - 1])


(n, m) = input().split()
n = int(n)
m = int(m)
l1 = [s for s in input().split()]
l2 = [s for s in input().split()]
k = int(input())
while k > 0:
	s = int(input())
	s1 = ''
	m1 = s % n
	m2 = s % m
	if m1 == 0:
		s1 += l1[-1]
	else:
		s1 += l1[m1 - 1]
	if m2 == 0:
		s1 += l2[-1]
	else:
		s1 += l2[m2 - 1]
	print(s1)
	k -= 1


import sys
from collections import defaultdict, deque
from math import sqrt

def input():
	return sys.stdin.readline()[:-1]
(n, m) = [int(x) for x in input().split()]
s = [x for x in input().split()]
t = [x for x in input().split()]
q = int(input())
for _ in range(q):
	i = int(input()) - 1
	print(s[i % n] + t[i % m])


(n, m) = map(int, str(input()).split(' '))
s = str(input()).split(' ')
t = str(input()).split(' ')
q = int(input())
for k in range(0, q):
	year = int(input())
	print(s[(year - 1) % n] + t[(year - 1) % m])


numberl = []
(n, m) = map(int, input().split())
star1 = list(map(str, input().split()))
starr2 = list(map(str, input().split()))
num = int(input())
for i in range(num):
	ele = int(input())
	numberl.append(ele)
for i in range(num):
	x = numberl[i] % n
	y = numberl[i] % m
	if x == 0:
		x = n
	if y == 0:
		y = m
	print(star1[x - 1] + starr2[y - 1])


(n, m) = map(int, input().split())
s = input().split()
t = input().split()
q = int(input())
year_list = []
answer = ''
for item in range(q):
	year_list.append(int(input()))
	s_index = year_list[item] % n - 1
	t_index = year_list[item] % m - 1
	answer = answer + s[int(s_index)] + t[int(t_index)] + '\n'
print(answer[:-1])


(n, m) = map(int, input().split())
l1 = list(map(str, input().split()))
l2 = list(map(str, input().split()))
q = int(input())
x = 0
y = 0
for _ in range(q):
	s = ''
	z = int(input())
	x = z % n
	y = z % m
	s += l1[x - 1] + l2[y - 1]
	print(s)


(n, m) = map(int, input().split())
ln = list(map(str, input().split()))
lm = list(map(str, input().split()))
dn = dict()
for i in range(1, len(ln) + 1):
	dn[i] = ln[i - 1]
dm = dict()
for i in range(1, len(lm) + 1):
	dm[i] = lm[i - 1]
for i in range(int(input())):
	case = int(input())
	rem1 = case % n
	rem2 = case % m
	if rem1 == 0:
		rem1 = n
	if rem2 == 0:
		rem2 = m
	print(dn[rem1] + dm[rem2])


[n, m] = map(int, input().split())
s1 = list(input().split())
s2 = list(input().split())
for _ in range(int(input())):
	num = int(input())
	print(s1[num % n - 1] + s2[num % m - 1])


(n, m) = [int(r) for r in input().split()]
s = input().split()
t = input().split()
q = int(input())
output = []
for _ in range(q):
	y = int(input())
	front = s[(y - 1) % n]
	back = t[(y - 1) % m]
	output.append(front + back)
print('\n'.join(output))


line1 = [int(i) for i in input().split(' ')]
N = line1[0]
M = line1[1]
N_list = input().split()
M_list = input().split()
q = int(input())
for i in range(0, q):
	target = int(input())
	print(N_list[target % N - 1] + M_list[target % M - 1])


from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
import sys, bisect, math, itertools, pprint, fractions
sys.setrecursionlimit(10 ** 8)
mod = 10 ** 9 + 7
mod2 = 998244353
INF = float('inf')

def inp():
	return int(sys.stdin.readline())

def inpl():
	return list(map(int, sys.stdin.readline().split()))

def inpln(n):
	return list((int(sys.stdin.readline()) for i in range(n)))
(n, m) = inpl()
s = input().split()
t = input().split()
name = [0 for i in range(n * m)]
for j in range(m):
	for i in range(n):
		name[j * n + i] = s[i]
for i in range(n):
	for j in range(m):
		name[i * m + j] += t[j]
q = inp()
for i in range(q):
	x = inp()
	print(name[(x - 1) % (n * m)])


(n, m) = map(int, input().split())
s = list(map(str, input().split()))
d = list(map(str, input().split()))
q = int(input())
j = 0
k = 0
l = []
p = n * m
for i in range(p):
	j = j % n
	k = k % m
	l.append(s[j] + d[k])
	j += 1
	k += 1
for i in range(q):
	z = int(input())
	z %= p
	print(l[z - 1])


input()
li1 = input().split()
li2 = input().split()
x = int(input())
for _ in range(x):
	n = int(input())
	print(li1[n % len(li1) - 1] + li2[n % len(li2) - 1])


from collections import *
(n, m) = map(int, input().split())
s1 = input()
t1 = input()
s = list(s1.split(' '))
t = list(t1.split(' '))
q = int(input())
for _ in range(q):
	year = int(input())
	sr = year % n
	tr = year % m
	sa = s[sr - 1]
	ta = t[tr - 1]
	ans = sa + ta
	print(ans)


(a, b) = map(int, input().split())
s = input().split()
t = input().split()
q = int(input())
for i in range(q):
	y = int(input())
	print(s[y % a - 1] + t[y % b - 1])


firstline = input().split()
n = int(firstline[0])
m = int(firstline[1])
s = input().split()
t = input().split()
q = int(input())
for i in range(0, q):
	y = int(input())
	index1 = y % n
	index2 = y % m
	print(s[index1 - 1] + t[index2 - 1])


import sys
input = lambda : sys.stdin.readline()
(n, m) = map(int, input().split())
a = input().split()
b = input().split()
for i in range(int(input())):
	d = int(input())
	print(a[(d - 1) % n] + b[(d - 1) % m])


(n, m) = input().split(' ')
n = int(n)
m = int(m)
lst1 = input()
lst1 = lst1.split(' ')
lst2 = input()
lst2 = lst2.split(' ')
left_input = int(input())
while left_input:
	given_year = int(input())
	i = given_year % n
	j = given_year % m
	print(lst1[i - 1] + lst2[j - 1])
	left_input -= 1


(n, m) = map(int, input().split())
s = input().split()
t = input().split()
for i in range(int(input())):
	inp = int(input())
	n1 = s[inp % len(s) - 1]
	n2 = t[inp % len(t) - 1]
	print(n1 + n2)


(n, m) = map(int, input().split())
s = input().strip().split()
t = input().strip().split()
k = int(input())
for i in range(k):
	year = int(input())
	ss = year % n - 1
	tt = year % m - 1
	string = str(s[ss] + t[tt])
	print(string)


(m, n) = input().split(' ')
(m, n) = (int(m), int(n))
s = [x for x in input().split(' ')]
t = [y for y in input().split(' ')]
queries = int(input())
for q in range(queries):
	year = int(input())
	(i, j) = (year % m - 1, year % n - 1)
	print(s[i] + t[j])


n = [int(_) for _ in input().split()]
a = [_ for _ in input().split()]
b = [_ for _ in input().split()]
for i in range(int(input())):
	s = int(input())
	v1 = s % n[0]
	v2 = s % n[1]
	print(''.join(a[v1 - 1]) + ''.join(b[v2 - 1]))


(n, m) = map(int, input().split())
n_list = list(input().split())
m_list = list(input().split())
years = int(input())
for i in range(years):
	year = int(input())
	answer1 = n_list[year % n - 1]
	answer2 = m_list[year % m - 1]
	print(answer1 + answer2)


(n, m) = input().split()
s = input().split()
t = input().split()
a = int(input())
q = len(s)
r = len(t)
d = ''
y = []
for x in range(a):
	g = input()
	y.append(g)
for h in y:
	d = str(s[int(h) % q - 1]) + str(t[int(h) % r - 1])
	print(d)


import sys
data = [ent.split() for ent in sys.stdin.readlines(0)]
(n, m) = (int(data[0][0]), int(data[0][1]))
firstPart = data[1]
secPart = data[2]
for i in range(4, len(data)):
	sys.stdout.write(firstPart[int(data[i][0]) % n - 1] + secPart[int(data[i][0]) % m - 1] + '\n')


(n, m) = [int(x) for x in input().split()]
s = [x for x in input().split()]
t = [x for x in input().split()]
qry = int(input())
for _ in range(qry):
	q = int(input())
	res = s[(q - 1) % n] + t[(q - 1) % m]
	print(res)


a = input()
b = input()
c = input()
d = input()
k = int(d)
lst1 = a.split(' ')
lst2 = b.split(' ')
lst3 = c.split(' ')
lst4 = ['']
x1 = int(lst1[0])
x2 = int(lst1[1])
n = 0
while n < k:
	e = input()
	h = int(e)
	y1 = h % x1
	y2 = h % x2
	z1 = lst2[y1 - 1]
	z2 = lst3[y2 - 1]
	print(z1 + z2)
	n += 1


from math import gcd
(n, m) = map(int, input().split())
ns = list(input().split())
ms = list(input().split())
q = int(input())
for _ in range(q):
	a = int(input())
	lcm = n * m // gcd(n, m)
	a %= lcm
	i = a % n
	j = a % m
	print(ns[i - 1] + ms[j - 1])


(n, m) = [int(x) for x in input().strip().split()]
S = [x for x in input().strip().split()]
T = [x for x in input().strip().split()]
q = int(input())
for i in range(q):
	y = int(input())
	s = y % len(S)
	t = y % len(T)
	print(S[s - 1] + T[t - 1])


from math import gcd
(n, m) = list(map(int, input().split()))
ar1 = list(input().split())
ar2 = list(input().split())
kek = n * m // gcd(n, m)
for _ in range(int(input())):
	t = int(input())
	t %= kek
	print(ar1[(t - 1) % n] + ar2[(t - 1) % m])


(n, m) = input().split()
n = int(n)
m = int(m)
l = input().split()
o = input().split()
ll = len(l)
oo = len(o)
if ll == n and oo == m:
	q = int(input())
	for i in range(q):
		y = int(input())
		x = y - 1
		if n == m:
			if y <= n:
				print(l[x] + o[x])
			if y > n:
				a = y % n - 1
				print(l[a] + o[a])
		elif n > m:
			if y <= m:
				print(l[x] + o[x])
			elif y > m and y <= n:
				a = y % m - 1
				print(l[x] + o[a])
			elif y > n:
				a = y % n - 1
				b = y % m - 1
				print(l[a] + o[b])
		elif n < m:
			if y <= n:
				print(l[x] + o[x])
			elif y > n and y <= m:
				a = y % n - 1
				print(l[a] + o[x])
			elif y > m:
				a = y % n - 1
				b = y % m - 1
				print(l[a] + o[b])


(n, m) = input().split()
sl = input().split()
tl = input().split()
q = int(input())
for i in range(q):
	y = int(input())
	s = y % int(n) - 1
	t = y % int(m) - 1
	print(sl[s] + tl[t])


(g, m) = map(int, input().split())
l = list(map(str, input().split()))
a = list(map(str, input().split()))
len1 = len(l)
len2 = len(a)
for _ in range(int(input())):
	n = int(input())
	print(l[n % len1 - 1] + a[n % len2 - 1])


(m, n) = map(int, input().split())
x = list(input().split())
y = list(input().split())
q = int(input())
for i in range(q):
	t = int(input())
	t -= 1
	print(x[t % m] + y[t % n])


from sys import stdin as s
(n, m) = map(int, s.readline().split())
(a, b) = (s.readline().split(), s.readline().split())
for i in range(int(s.readline())):
	t = int(s.readline())
	x = a[(t - 1) % n]
	y = b[(t - 1) % m]
	print(x + y)


(n, m) = map(int, input().split())
l1 = list(map(str, input().split()))
l2 = list(map(str, input().split()))
q = int(input())
L = []
i = 0
j = 0
while len(L) < len(l1) * len(l2):
	s1 = l1[i % len(l1)]
	s2 = l2[j % len(l2)]
	s = s1 + s2
	L.append(s)
	i += 1
	j += 1
for i in range(q):
	y = int(input())
	print(L[y % len(L) - 1])


(n, m) = map(int, input().split())
s = input().split()
t = input().split()
q = int(input())
while q > 0:
	q = q - 1
	y = int(input())
	year = s[y % n - 1] + t[y % m - 1]
	print(year)


(n, m) = list(map(int, input().split()))
a = input().split()
b = input().split()
q = int(input())
for i in range(q):
	y = int(input())
	ind_a = y % n - 1
	ind_b = y % m - 1
	print(a[ind_a] + b[ind_b])


(n, m) = map(int, input().split())
list_1 = input().split()
list_2 = input().split()
for i in range(int(input())):
	x = int(input()) - 1
	print(list_1[x % n] + list_2[x % m])


(n, m) = map(int, input().split())
s1 = input().split()
s2 = input().split()
l = []
for i in range(n * m):
	l.append(s1[i % n] + s2[i % m])
for i in range(int(input())):
	k = int(input())
	print(l[(k - 1) % (n * m)])


(n, m) = map(int, input().split(' '))
S = input().split(' ')
T = input().split(' ')
q = int(input())
for i in range(q):
	j = int(input())
	a = j % n
	b = j % m
	k = S[a - 1] + T[b - 1]
	print(k)


def main():
	(n, m) = list(map(int, input().split()))
	s = list(input().split())
	t = list(input().split())
	q = int(input())
	in_ls = []
	for i in range(q):
		tmp = int(input())
		in_ls.append(tmp)
	for i in range(q):
		year = in_ls[i]
		ans = s[(year - 1) % n] + t[(year - 1) % m]
		print(ans)
main()


I = input
I()
s = I().split()
t = I().split()
exec(int(I()) * 'y=int(I())-1;print(s[y%len(s)]+t[y%len(t)]);')


(a, b) = map(int, input().split())
s1 = input().split()
s2 = input().split()
numyears = int(input())
years = []
for i in range(numyears):
	years.append(int(input()))
for year in years:
	c1 = ''
	c2 = ''
	output = ''
	if year <= a:
		c1 = s1[year - 1]
	elif year > a:
		c1 = s1[year % a - 1]
	if year <= b:
		c2 = s2[year - 1]
	elif year > b:
		c2 = s2[year % b - 1]
	output = c1 + c2
	print(output)


(n, m) = map(int, input().split())
ai = list(map(str, input().split()))
bi = list(map(str, input().split()))
q = int(input())
for i in range(q):
	y = int(input())
	print(ai[y % n - 1] + bi[y % m - 1])


(n, m) = map(int, input().split())
s = input().split()
t = input().split()
i = 0
j = 0
d = {}
idx = 0
while len(d) < n * m:
	d[idx] = s[i] + t[j]
	idx += 1
	i += 1
	j += 1
	if i == n:
		i = 0
	if j == m:
		j = 0
q = int(input())
for _ in range(q):
	year = int(input()) - 1
	print(d[year % (n * m)])


(n, m) = [int(x) for x in input().split()]
s = list(input().split())
t = list(input().split())
for i in range(int(input())):
	p = ''
	a = int(input())
	b = a % n
	c = a % m
	if b == 0:
		p += s[-1]
	else:
		p += s[b - 1]
	if c == 0:
		p += t[-1]
	else:
		p += t[c - 1]
	print(p)


import sys
input = sys.stdin.readline

def main():
	(N, M) = [int(x) for x in input().split()]
	S = [x for x in input().strip().split()]
	T = [x for x in input().strip().split()]
	q = int(input())
	for _ in range(q):
		a = int(input())
		print(S[a % N - 1] + T[a % M - 1])
main()


(n, m) = map(int, input().split())
s = input().split()
t = input().split()
t1 = int(input())
for i in range(t1):
	q = int(input())
	n1 = q % n
	m1 = q % m
	res1 = s[n1 - 1]
	res2 = t[m1 - 1]
	ans = res1 + res2
	print(ans)


import math
from decimal import Decimal
import heapq
import copy
from collections import deque

def na():
	n = int(input())
	b = [int(x) for x in input().split()]
	return (n, b)

def nab():
	n = int(input())
	b = [int(x) for x in input().split()]
	c = [int(x) for x in input().split()]
	return (n, b, c)

def dv():
	(n, m) = map(int, input().split())
	return (n, m)

def da():
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	return (n, m, a)

def dva():
	(n, m) = map(int, input().split())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	return (n, m, b)

def eratosthenes(n):
	sieve = list(range(n + 1))
	for i in sieve:
		if i > 1:
			for j in range(i + i, len(sieve), i):
				sieve[j] = 0
	return sorted(set(sieve))

def lol(lst, k):
	k = k % len(lst)
	ret = [0] * len(lst)
	for i in range(len(lst)):
		if i + k < len(lst) and i + k >= 0:
			ret[i] = lst[i + k]
		if i + k >= len(lst):
			ret[i] = lst[i + k - len(lst)]
		if i + k < 0:
			ret[i] = lst[i + k + len(lst)]
	return ret

def nm():
	n = int(input())
	b = [int(x) for x in input().split()]
	m = int(input())
	c = [int(x) for x in input().split()]
	return (n, b, m, c)

def dvs():
	n = int(input())
	m = int(input())
	return (n, m)

def fact(a, b):
	c = []
	ans = 0
	f = int(math.sqrt(a))
	for i in range(1, f + 1):
		if a % i == 0:
			c.append(i)
	l = len(c)
	for i in range(l):
		c.append(a // c[i])
	for i in range(len(c)):
		if c[i] <= b:
			ans += 1
	if a / f == f and b >= f:
		return ans - 1
	return ans
import math
from decimal import Decimal
import heapq
from collections import deque

def na():
	n = int(input())
	b = [int(x) for x in input().split()]
	return (n, b)

def nab():
	n = int(input())
	b = [int(x) for x in input().split()]
	c = [int(x) for x in input().split()]
	return (n, b, c)

def dv():
	(n, m) = map(int, input().split())
	return (n, m)

def da():
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	return (n, m, a)

def dva():
	(n, m) = map(int, input().split())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	return (n, m, b)

def eratosthenes(n):
	sieve = list(range(n + 1))
	for i in sieve:
		if i > 1:
			for j in range(i + i, len(sieve), i):
				sieve[j] = 0
	return sorted(set(sieve))

def lol(lst, k):
	k = k % len(lst)
	ret = [0] * len(lst)
	for i in range(len(lst)):
		if i + k < len(lst) and i + k >= 0:
			ret[i] = lst[i + k]
		if i + k >= len(lst):
			ret[i] = lst[i + k - len(lst)]
		if i + k < 0:
			ret[i] = lst[i + k + len(lst)]
	return ret

def nm():
	n = int(input())
	b = [int(x) for x in input().split()]
	m = int(input())
	c = [int(x) for x in input().split()]
	return (n, b, m, c)

def dvs():
	n = int(input())
	m = int(input())
	return (n, m)

def fact(a, b):
	c = []
	ans = 0
	f = int(math.sqrt(a))
	for i in range(1, f + 1):
		if a % i == 0:
			c.append(i)
	l = len(c)
	for i in range(l):
		c.append(a // c[i])
	for i in range(len(c)):
		if c[i] <= b:
			ans += 1
	if a / f == f and b >= f:
		return ans - 1
	return ans
(n, m) = map(int, input().split())
a = list(input().split())
b = list(input().split())
for i in range(int(input())):
	y = int(input())
	d = y % n
	dd = y % m
	print(a[d - 1] + b[dd - 1])


(m, n) = map(int, input().split())
a = list(map(str, input().split()))
b = list(map(str, input().split()))
t = int(input())
for i in range(t):
	k = int(input())
	p = k % n
	q = k % m
	if k <= m and k <= n:
		print(a[k - 1] + b[k - 1])
	elif k < m and k > n:
		print(a[k - 1] + b[p - 1])
	elif k > m and k < n:
		print(a[q - 1] + b[k - 1])
	elif k > m and k > n:
		print(a[q - 1] + b[p - 1])
	elif k == m and k > n:
		print(a[k - 1] + b[p - 1])
	elif k > m and k == n:
		print(a[q - 1] + b[k - 1])


(n, m) = map(int, input().split())
s = [i for i in input().split()]
t = [i for i in input().split()]
q = int(input())
for i in range(q):
	num = int(input())
	index1 = num - num // n * n
	index2 = num - num // m * m
	print(s[index1 - 1] + t[index2 - 1])


(n, k) = input().split()
n = int(n)
k = int(k)
xx = input()
kk = input()
x = list(xx.split())
y = list(kk.split())
q = int(input())
for t in range(0, q, 1):
	year = int(input())
	thd = x[year % len(x) - 1]
	apsr = y[year % len(y) - 1]
	print(thd + apsr)


from collections import defaultdict, deque
from itertools import permutations
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
from copy import deepcopy
int_input = lambda : int(stdin.readline())
string_input = lambda : stdin.readline()
multi_int_input = lambda : map(int, stdin.readline().split())
multi_input = lambda : stdin.readline().split()
list_input = lambda : list(map(int, stdin.readline().split()))
string_list_input = lambda : list(string_input())
MOD = pow(10, 9) + 7
(n, m) = multi_int_input()
s = input().split()
t = input().split()
q = int_input()
for _ in range(q):
	year = int_input()
	print(s[year % n - 1] + t[year % m - 1])


(m, n) = (int(i) for i in input().split())
s = input().split()
t = input().split()
a = int(input())
for i in range(a):
	b = int(input())
	bs = b % len(s) - 1
	bt = b % len(t) - 1
	print(s[bs] + t[bt])


(n, m) = map(int, input().split())
a = list(map(str, input().split()))
b = list(map(str, input().split()))
for q in range(int(input())):
	s = int(input())
	s = s % (n * m)
	x = s % n - 1
	if x == -1:
		x = n - 1
	y = s % m - 1
	if y == -1:
		y = m - 1
	print(a[x] + b[y])


(a, b) = map(int, input().split())
A = list(map(str, input().split()))
B = list(map(str, input().split()))
Ans = []
n = int(input())
la = len(A)
lb = len(B)
for i in range(n):
	x = int(input()) - 1
	Ans.append(A[x % la] + B[x % lb])
for an in Ans:
	print(an)


from collections import defaultdict
d1 = defaultdict(int)
d2 = defaultdict(int)
(n, m) = map(int, input().split())
l1 = list(map(str, input().split()))
for i in range(n):
	d1[i] = l1[i]
l2 = list(map(str, input().split()))
for i in range(m):
	d2[i] = l2[i]
q = int(input())
for i in range(q):
	p = int(input())
	p -= 1
	print(d1[p % n] + d2[p % m])


from math import *
from copy import *
from string import *
from random import *
from sys import stdin
from sys import maxsize
from operator import *
from itertools import *
from collections import Counter
import math

def bin1(l, r, k, t, b, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		v = k ** mid
		if v == val:
			return v
		elif v > val:
			ans = mid
			return bin1(mid + 1, r, k, t, b, val, ans)
		else:
			return bin1(l, mid - 1, k, t, b, val, ans)

def bin2(l, r, k, t, b, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		v = t * k ** mid + b * mid
		if v == val:
			return v
		elif v > val:
			ans = mid
			return bin2(l, mid - 1, k, t, b, val, ans)
		else:
			return bin2(mid + 1, r, k, t, b, val, ans)

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	l = []
	for i in range(2, n + 1):
		if prime[i]:
			l.append(i)
	return l

def bin(l, r, ll, val):
	if l > r:
		return -1
	else:
		mid = (l + r) // 2
		if val >= ll[mid][0] and val <= ll[mid][1]:
			return mid
		elif val < ll[mid][0]:
			return bin(l, mid - 1, ll, val)
		else:
			return bin(mid + 1, r, ll, val)

def deci(n):
	s = ''
	while n != 0:
		if n % 2 == 0:
			n = n // 2
			s = '0' + s
		else:
			n = n // 2
			s = '1' + s
	return s

def diff(s1, s2):
	if len(s1) < len(s2):
		v = len(s1)
		while v != len(s2):
			s1 = '0' + s1
			v = v + 1
	else:
		v = len(s2)
		while v != len(s1):
			s2 = '0' + s2
			v = v + 1
	c = 0
	for i in range(len(s1)):
		if s1[i:i + 1] != s2[i:i + 1]:
			c = c + 1
	return c
from sys import stdin, stdout

def fac(a, b):
	v = a
	while a != b:
		v *= a - 1
		a = a - 1
	return v

def bino(l, r, n):
	if l > r:
		return -1
	else:
		mid = (l + r) // 2
		val1 = math.log(n / mid + 1, 2)
		val2 = int(val1)
		if val1 == val2:
			return val1
		elif val1 < 1.0:
			return bino(l, mid - 1, n)
		else:
			return bino(mid + 1, r, n)

def binary(l, r, ll, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		if ll[mid] == val:
			return ll[mid]
		elif ll[mid] < val:
			ans = ll[mid]
			return binary(mid + 1, r, ll, val, ans)
		else:
			return binary(l, mid - 1, ll, val, ans)

def check(n):
	v = 1
	while n != 0:
		if n % 10 == 0 or n % 10 == 1:
			n = n // 10
		else:
			v = 0
			break
	return v
(n, m) = map(int, input().split(' '))
l1 = list(map(str, input().split(' ')))
l2 = list(map(str, input().split(' ')))
q = int(input())
for i in range(q):
	y = int(input())
	s = l1[y % n - 1] + l2[y % m - 1]
	print(s)


(n, m) = input().strip().split(' ')
(n, m) = (int(n), int(m))
s = input().strip().split(' ')
t = input().strip().split(' ')
q = int(input())
queries = list()
for i in range(q):
	queries.append(int(input()))
for qu in queries:
	first = qu % n
	last = qu % m
	final_name = s[first - 1] + t[last - 1]
	print(final_name)


(l, m) = map(int, input().split())
(s1, s2) = (input().split(), input().split())
for _ in range(int(input())):
	y = int(input())
	r = s1[y % len(s1) - 1] + s2[y % len(s2) - 1]
	print(r)


import sys
input = sys.stdin.readline
(n, m) = map(int, input().rstrip().split())
s = list(map(str, input().split()))
t = list(map(str, input().split()))
q = int(input())
for _ in range(q):
	y = int(input())
	a = (y - 1) % n
	b = (y - 1) % m
	print(s[a] + t[b])


(n, m) = map(int, input().split())
ln = list(map(str, input().split()))
lm = list(map(str, input().split()))
total = int(input())
for _ in range(total):
	y = int(input())
	(n1, n2) = (y - 1, y - 1)
	if not y <= n:
		n1 = y - 1 - y // n * n
	if not y <= m:
		n2 = y - 1 - y // m * m
	print(ln[n1] + lm[n2])


(n, m) = map(int, input().split())
s_n = input().split()
s_m = input().split()
t = int(input())
for _ in range(t):
	y = int(input())
	print(s_n[y % len(s_n) - 1] + s_m[y % len(s_m) - 1])


r = input().split()
n = int(r[0])
m = int(r[1])
s = input().split()
t = input().split()
q = int(input())
for i in range(q):
	c = int(input())
	print(s[(c - 1) % n] + t[(c - 1) % m])


first_line = input().split(' ')
n = int(first_line[0])
m = int(first_line[1])
s_array = input().split(' ')
t_array = input().split(' ')
q = int(input())
years_array = []
for i in range(q):
	years_array.append(int(input()))
for year in years_array:
	s_index = None
	t_index = None
	if year <= n:
		s_index = year - 1
	else:
		s_index = year % n - 1
	if year <= m:
		t_index = year - 1
	else:
		t_index = year % m - 1
	print(s_array[s_index] + t_array[t_index])


nm = input().split()
n = int(nm[0])
m = int(nm[1])
s = input().split()
t = input().split()
q = int(input())
for x in range(q):
	year = int(input())
	nremainder = year % n
	mremainder = year % m
	sname = s[nremainder - 1]
	tname = t[mremainder - 1]
	print(sname + tname)


(n, m) = map(int, input().split())
N = list(map(str, input().split()))
M = list(map(str, input().split()))
for _ in range(int(input())):
	x = int(input())
	print(N[(x - 1) % n] + M[(x - 1) % m])


(n1, n2) = map(int, input().split())
s1 = []
s2 = []
s1 = input().split()
s2 = input().split()
t = int(input())
while t > 0:
	n = int(input())
	print(s1[n % n1 - 1] + s2[n % n2 - 1])
	t = t - 1


from math import gcd
(n, m) = map(int, input().split())
s = list(input().split())
t = list(input().split())
a = []
x = 0
y = 0
p = n * m // gcd(n, m)
for i in range(p):
	a.append(s[x] + t[y])
	x += 1
	x %= n
	y += 1
	y %= m
for _ in range(int(input())):
	x = int(input())
	x -= 1
	x %= p
	print(a[x])


(numstr1, numstr2) = input().split(' ')
numstr1 = int(numstr1)
numstr2 = int(numstr2)
prefixlist = []
suffixlist = []
prefixlist = input().split(' ')
suffixlist = input().split(' ')
numyears = input()

def Gapja(year):
	prefix = prefixlist[(year - 1) % numstr1]
	suffix = suffixlist[(year - 1) % numstr2]
	return prefix + suffix
for i in range(int(numyears)):
	print(Gapja(int(input())))


(n, m) = map(int, input().split())
n_names = list(map(str, input().split()))
m_names = list(map(str, input().split()))
q = int(input())
for i in range(q):
	res = ''
	no = int(input())
	x = no % n
	y = no % m
	if x == 0:
		res += n_names[-1]
	else:
		res += n_names[x - 1]
	if y == 0:
		res += m_names[-1]
	else:
		res += m_names[y - 1]
	print(res)


(n, m) = [int(i) for i in input().split()]
s = [st for st in input().split()]
t = [st for st in input().split()]
for _ in range(int(input())):
	q = int(input()) - 1
	print(s[q % n] + t[q % m])


(N, M) = [int(x) for x in input().split(' ')]
A = input().split(' ')
B = input().split(' ')
Q = int(input())
for i in range(Q):
	q = int(input())
	q -= 1
	print(A[q % N] + B[q % M])


(a_no, b_no) = map(int, input().split())
a = input()
b = input()
p = int(input())
l = []
for i in range(p):
	l.append(int(input()))
a_list = a.split()
b_list = b.split()
for i in range(p):
	print(a_list[(l[i] - 1) % len(a_list)] + b_list[(l[i] - 1) % len(b_list)])


numeros = list(map(int, input().split(' ')))
string1 = list(map(str, input().split(' ')))
string2 = list(map(str, input().split(' ')))
q = int(input())
for k in range(q):
	n = int(input())
	indice1 = n % len(string1) - 1
	indice2 = n % len(string2) - 1
	concatena = string1[indice1] + string2[indice2]
	print(concatena)


(n, m) = map(int, input().split())
a = input().split()
b = input().split()
q = int(input())
for i in range(q):
	s = int(input())
	g = s % n
	h = s % m
	print(a[g - 1] + b[h - 1])


def solve(s, t, year):
	index_s = (year - 1) % len(s)
	index_t = (year - 1) % len(t)
	return s[index_s] + t[index_t]
(n, m) = map(int, input().split(' '))
s = input().split(' ')
t = input().split(' ')
q = int(input())
for i in range(q):
	year = int(input())
	y = solve(s, t, year)
	print(y)


(n, m) = map(int, input().split())
n1 = input().split()
m1 = input().split()
k = int(input())
for i in range(k):
	j = int(input())
	str1 = n1[j % n - 1]
	str2 = m1[j % m - 1]
	print(str1 + str2)


(s, t) = map(int, input().split())
S = input().split()
T = input().split()
n = int(input())
for _ in range(n):
	year = int(input())
	print(S[year % s - 1] + T[year % t - 1])


n = input()
(n, m) = n.split(' ')
s = input()
s = s.split(' ')
t = input()
t = t.split(' ')
q = int(input())
count = 0
y_list = []
while count < q:
	x = int(input())
	y_list.append(x)
	count += 1
for x in y_list:
	ans = ''
	if x <= int(n):
		ans += s[x - 1]
		if x <= int(m):
			ans += t[x - 1]
		else:
			r = x % int(m)
			ans += t[r - 1]
	else:
		r = x % int(n)
		ans += s[r - 1]
		if x <= int(m):
			ans += t[x - 1]
		else:
			a = x % int(m)
			ans += t[a - 1]
	print(ans)


from math import fmod as mod
[n, m] = map(int, input().split())
s = list(map(str, input().split()))
t = list(map(str, input().split()))
for i in range(int(input())):
	h = int(input())
	print(s[int(mod(h, n)) - 1] + t[int(mod(h, m)) - 1])


(n, m) = map(int, input().split())
s = list(map(str, input().split()))
t = list(map(str, input().split()))
q = int(input())

def name(n, m, s, t, q):
	for x in range(q):
		year = int(input())
		a = year % n
		b = year % m
		print(s[a - 1] + t[b - 1])
name(n, m, s, t, q)


(n, m) = map(int, input().split())
S = input().split()
T = input().split()
q = int(input())

def get_name(year):

	def get_start_name(year):
		if year > len(S):
			y = year % len(S)
			if y == 0:
				return S[-1]
			return get_start_name(y)
		return S[year - 1]

	def get_end_name(year):
		if year > len(T):
			y = year % len(T)
			if y == 0:
				return T[-1]
			return get_end_name(y)
		return T[year - 1]
	return get_start_name(year) + get_end_name(year)
for _ in range(q):
	year = int(input())
	print(get_name(year))


(n, m) = input().split()
n = int(n)
m = int(m)
s1 = input().split()
s2 = input().split()
q = int(input())
while q:
	q1 = int(input())
	print(s1[(q1 - 1) % n] + s2[(q1 - 1) % m])
	q -= 1


(n, m) = map(int, input().split())
s = list(map(str, input().split()))
t = list(map(str, input().split()))

def check(n, m, s, t, o):
	if o < n:
		x = s[o - 1]
	else:
		c = o % n
		x = s[c - 1]
	if o < m:
		y = t[o - 1]
	else:
		c2 = o % m
		y = t[c2 - 1]
	print(x + y)
i = int(input())
for i2 in range(i):
	o = int(input())
	check(n, m, s, t, o)


input = __import__('sys').stdin.readline
MIS = lambda : map(int, input().split())
(n, m) = MIS()
A = input().split()
B = input().split()
for TEST in range(int(input())):
	y = int(input()) - 1
	print(A[y % len(A)] + B[y % len(B)])


numberl = []
(p, q) = map(int, input().split())
starr1 = list(map(str, input().split()))
starr2 = list(map(str, input().split()))
num = int(input())
for i in range(num):
	ele = int(input())
	numberl.append(ele)
for i in range(num):
	x = numberl[i] % p
	y = numberl[i] % q
	if x == 0:
		x = p
	if y == 0:
		y = q
	print(starr1[x - 1] + starr2[y - 1])


(n, m) = map(int, input().split())
s = list(map(str, input().split()))
t = list(map(str, input().split()))
k = n * m
l = 0
r = 0
ans = []
for i in range(k):
	temp = s[l] + t[r]
	l = l + 1
	r = r + 1
	if l == n:
		l = 0
	if r == m:
		r = 0
	ans.append(temp)
q = int(input())
for i in range(q):
	y = int(input())
	y = y % k
	print(ans[y - 1])


(n, m) = map(int, input().split())
a = [str(i) for i in input().split()][:n]
b = [str(i) for i in input().split()][:m]
for i in range(int(input())):
	d = int(input())
	e = d % len(a)
	f = d % len(b)
	if e == 0 and f == 0:
		print(a[-1] + b[-1])
	elif e == 0 and f != 0:
		print(a[-1] + b[f - 1])
	elif e != 0 and f == 0:
		print(a[e - 1] + b[-1])
	else:
		print(a[e - 1] + b[f - 1])


def R():
	return map(int, input().split())

def I():
	return int(input())

def S():
	return str(input())

def L():
	return list(R())
from collections import Counter
import math
import sys
from itertools import permutations
(n, m) = R()
a = list(map(str, input().split()))
b = list(map(str, input().split()))
ans = [''] * 2020
for i in range(n * m):
	ans[i] = a[i % n] + b[i % m]
for _ in range(I()):
	j = (I() - 1) % (n * m)
	print(ans[j])


import math
import sys
import re
(m, n) = map(int, input().rstrip().split())
a = list(map(str, input().rstrip().split()))
b = list(map(str, input().rstrip().split()))
c = int(input())
for x in range(c):
	i = int(input())
	m1 = i % m
	n1 = i % n
	s = ''
	if m1 == 0:
		s = s + a[-1]
	else:
		s = s + a[m1 - 1]
	if n1 == 0:
		s = s + b[-1]
	else:
		s = s + b[n1 - 1]
	print(s)


def func(l1, l2, num):
	print(l1[num % len(l1) - 1] + l2[num % len(l2) - 1])

def main():
	(n, m) = map(int, input().split())
	l1 = list(map(str, input().split()))
	l2 = list(map(str, input().split()))
	k = int(input())
	for i in range(k):
		func(l1, l2, int(input()))
t = 1
for i in range(t):
	main()


(x, y) = map(int, input().split())
z = []
l = list(map(str, input().split()))
m = list(map(str, input().split()))
for i in range(0, x * y):
	z.append(l[i % x] + m[i % y])
c = x * y
q = int(input())
while q:
	w = int(input())
	print(z[w % c - 1])
	q -= 1


gi = lambda : list(map(int, input().split()))
(n, m) = gi()
s = input().split()
t = input().split()
for k in range(gi()[0]):
	(y,) = gi()
	y -= 1
	print(s[y % n] + t[y % m])


xx = input()
n = int(xx.split(' ')[0])
m = int(xx.split(' ')[1])
str1 = input()
l1 = str1.split(' ')
str2 = input()
l2 = str2.split(' ')
q = int(input())
for i in range(q):
	val = int(input())
	print(l1[(val - 1) % n] + l2[(val - 1) % m])


(n, m) = map(int, input().split())
st1 = input().split()
st2 = input().split()
p = int(input())
for i in range(p):
	a = int(input())
	c = a % n
	b = a % m
	print(st1[c - 1] + st2[b - 1])


(n, m) = [int(i) for i in input().split()]
arr1 = input().split(' ')
arr2 = input().split(' ')
t = int(input())
for i in range(t):
	num = int(input()) - 1
	print(arr1[num % n] + arr2[num % m])


nm = input()
nsize = int(nm.split()[0])
msize = int(nm.split()[1])
n = input()
m = input()
n = n.split()
m = m.split()
nq = int(input())
q = []
for i in range(nq):
	q.append(int(input()))
for i in range(nq):
	nval = n[q[i] % nsize - 1]
	mval = m[q[i] % msize - 1]
	print(nval + mval)


(n, m) = map(int, input().split())
l1 = list(input().split())
l2 = list(input().split())
q = int(input())
for i in range(q):
	s = int(input())
	x = s % n
	y = s % m
	if x == 0:
		x = n
	if y == 0:
		y = m
	print(l1[x - 1] + l2[y - 1])


x = input()
xx = x.split()
n = int(xx[0])
m = int(xx[1])
x = input()
a = x.split()
x = input()
b = x.split()
q = int(input())
s = []
for knb in range(0, q):
	t = int(input())
	x = t % n
	y = t % m
	s.append(a[x - 1] + b[y - 1])
for i in s:
	print(i)


def readint():
	return int(input())

def readlistint():
	return list(map(int, input().split()))

def readgridint(rows):
	grid = []
	for idx in range(rows):
		col = list(map(int, input().split()))
		grid.append(col)
	return grid

def readliststr():
	return list(input().strip().split())

def main():
	(N, M) = readlistint()
	F = readliststr()
	S = readliststr()
	lines = readint()
	for line in range(lines):
		year = readint() - 1
		print(F[year % len(F)] + S[year % len(S)])
main()


(n1, n2) = input().split()
n1 = int(n1)
n2 = int(n2)
s = input().split()
t = input().split()
total = int(input())
years = []
for i in range(total):
	years.append(int(input()))
for year in years:
	index1 = year % n1
	index2 = year % n2
	print(s[index1 - 1] + t[index2 - 1])


(n, m) = map(int, input().split(' '))
s = list(input().split(' '))
t = list(input().split(' '))
for _ in range(int(input())):
	y = int(input())
	p = y
	if y < n:
		a = s[y - 1]
	else:
		y = y % n
		a = s[y - 1]
	if p < m:
		b = t[p - 1]
	else:
		p = p % m
		b = t[p - 1]
	print(a + b)


(n, m) = map(int, input().split())
s = input().split(' ')
t = input().split(' ')

def ko(g):
	a = g % n
	b = g % m
	return s[a - 1] + t[b - 1]
q = int(input())
c = []
for i in range(q):
	h = int(input())
	c.append(h)
for i in c:
	print(ko(i))


input()
s = input().split()
l = input().split()
for i in range(int(input())):
	q = int(input()) - 1
	print(s[q % len(s)] + l[q % len(l)])


from itertools import cycle
lengths = input().split(' ')
str1 = input().split(' ')
str2 = input().split(' ')
ans = []
reps = int(input())
while reps > 0:
	x = int(input())
	ans.append(str1[x % int(lengths[0]) - 1] + str2[x % int(lengths[1]) - 1])
	reps -= 1
for x in ans:
	print(x)


(n, m) = map(int, input().split())
s1 = list(input().split())
s2 = list(input().split())
s3 = []
t = n * m
i = 0
j = 0
for _ in range(t):
	s3.append(s1[i] + s2[j])
	i = (i + 1) % n
	j = (j + 1) % m
q = int(input())
for _ in range(q):
	year = int(input())
	year = year % t
	print(s3[year - 1])


(n, m) = map(int, input().split())
s = input().split()
t = input().split()
for _ in range(int(input())):
	x = int(input())
	ans = s[x % n - 1] + t[x % m - 1]
	print(ans)


(LenS, LenT) = map(int, input().split())
(S, T) = (list(input().split()), list(input().split()))
queries = int(input())
for _ in range(queries):
	year = int(input())
	print(S[(year - 1) % LenS] + T[(year - 1) % LenT])


(n, m) = tuple(map(int, input().strip().split()))
s = input().strip().split()
t = input().strip().split()
q = int(input())
for _ in range(q):
	yr = int(input())
	ni = yr % n - 1
	mi = yr % m - 1
	print(s[ni] + t[mi])


nm = [int(x) for x in input().split()]
s = [x for x in input().split()]
t = [x for x in input().split()]
q = int(input())
years = []
for i in range(q):
	years.append(int(input()))
for i in years:
	print(s[i % nm[0] - 1], end='')
	print(t[i % nm[1] - 1])


(n, m) = [int(x) for x in input().split()]
s = [x for x in input().split()]
t = [x for x in input().split()]
q = int(input())
for _ in range(0, q):
	y = int(input()) - 1
	print(s[y % n] + t[y % m])


(n, m) = map(int, input().split())
l1 = list(map(str, input().split()))
l2 = list(map(str, input().split()))
y = int(input())
while y > 0:
	y -= 1
	x = int(input())
	print(str(l1[x % n - 1]) + str(l2[x % m - 1]))


(n, m) = map(int, input().split())
s = [x for x in input().strip().split()]
t = [x for x in input().strip().split()]
for _ in range(int(input())):
	k = int(input())
	(ind1, ind2) = (0, 0)
	if k % n == 0:
		ind1 = n - 1
	else:
		ind1 = k % n - 1
	if k % m == 0:
		ind2 = m - 1
	else:
		ind2 = k % m - 1
	print(s[ind1] + t[ind2])


(n, m) = input().split(' ')
n = int(n)
m = int(m)
list_s = input().split(' ')
list_t = input().split(' ')
q = int(input())
for i in range(q):
	y = int(input())
	ans1 = list_s[y % n - 1]
	ans2 = list_t[y % m - 1]
	ans = ans1 + ans2
	print(ans)


[N, M] = list(map(int, input().split()))
S = input().split()
T = input().split()
si = 0
ti = 0
st_to_index = [None for _ in range(N * M)]
for idx in range(N * M):
	st_to_index[idx] = S[idx % N] + T[idx % M]
Q = int(input())
for _ in range(Q):
	q = int(input())
	print(st_to_index[(q - 1) % (N * M)])


(n, m) = map(int, input().split())
l1 = list(input().split())
l2 = list(input().split())
t = int(input())
for _ in range(t):
	x = int(input())
	first = x % n
	second = x % m
	if first == 0:
		first = n
	if second == 0:
		second = m
	print(l1[first - 1] + l2[second - 1])


m = list(map(int, input().split()))
s = list(map(str, input().split()))
t = list(map(str, input().split()))
q = int(input())
for i in range(0, q):
	y = int(input())
	if y % m[0] != 0:
		j = y % m[0]
	else:
		j = m[0]
	if y % m[1] != 0:
		k = y % m[1]
	else:
		k = m[1]
	print(s[j - 1] + t[k - 1])


(n, m) = map(int, input().split())
s1 = input().split()
s2 = input().split()
for i in range(int(input())):
	t = int(input())
	a = t - t // n * n
	b = t - t // m * m
	print(s1[a - 1] + s2[b - 1])


(n, t) = map(int, input().split())
a = list(map(str, input().split()))
b = list(map(str, input().split()))
q = int(input())
while q:
	y = int(input())
	y -= 1
	print(a[y % n], end='')
	print(b[y % t])
	q -= 1


(n, m) = map(int, input().split())
s = [i for i in input().split(' ')]
t = [i for i in input().split(' ')]
q = int(input())
for i in range(q):
	y = int(input())
	idx_s = y % n
	idx_t = y % m
	print(s[idx_s - 1] + t[idx_t - 1])


from fractions import Fraction
(n, m) = [int(x) for x in input().split()]
a = [x for x in input().split()]
b = [x for x in input().split()]
nod = m // Fraction(n, m).denominator
nok = n * m // nod
for q in range(int(input())):
	y = int(input()) - 1
	y %= nok
	(n1, m1) = [0] * 2
	n1 = y % n
	m1 = y % m
	print(a[n1] + b[m1])


def mi():
	return map(int, input().split())
(n, m) = mi()
a = list(input().split())
b = list(input().split())
la = len(a)
lb = len(b)
for _ in range(int(input())):
	y = int(input()) - 1
	print(a[y % la] + b[y % lb])


from sys import stdin
(n, m) = map(int, stdin.readline().split())
l = list(map(str, stdin.readline().split()))
l1 = list(map(str, stdin.readline().split()))
q = int(stdin.readline().rstrip())
while q > 0:
	k = int(stdin.readline().rstrip())
	print(l[(k - 1) % n] + l1[(k - 1) % m])
	q -= 1


n = map(int, input().split())
l1 = input().split()
l2 = input().split()
nn = int(input())
for i in range(nn):
	y = int(input()) - 1
	print(l1[y % len(l1)] + l2[y % len(l2)])


(n, m) = input().split()
(n, m) = (int(n), int(m))
a = input().split()
b = input().split()
t = int(input())
for _ in range(t):
	c = int(input()) - 1
	print(a[c % n] + b[c % m])


def arr_inp():
	return [int(x) for x in stdin.readline().split()]
from sys import stdin
(n, m) = arr_inp()
(s, t) = [[str(x) for x in stdin.readline().split()] for i in range(2)]
for i in range(int(input())):
	x = int(input())
	print(s[x % n - 1] + t[x % m - 1])


(n, m) = map(int, input().split())
s = input().split()
t = input().split()
q = int(input())
for z in range(q):
	x = int(input()) - 1
	print(s[x % n] + t[x % m])


(n, m) = map(int, input().split())
s = list(map(str, input().strip().split()))[:n]
t = list(map(str, input().strip().split()))[:m]
q = int(input())
for i in range(q):
	a = int(input())
	print(s[(a % n + (n - 1)) % n] + t[(a % m + (m - 1)) % m])


a = input()
b = [int(x) for x in a.split()]
c = input()
d = c.split()
e = input()
f = e.split()
g = int(input())
for i in range(0, g):
	angka = int(input())
	p1 = angka % b[0]
	p2 = angka % b[1]
	hasil = d[p1 - 1] + f[p2 - 1]
	print(hasil)


(n, p) = map(int, input().split())
a = list(map(str, input().split()))
b = list(map(str, input().split()))
i = int(input())
for _ in range(i):
	c = int(input())
	print('%s%s' % (a[(c - 1) % len(a)], b[(c - 1) % len(b)]))


def solve(s, t, ns, nt, yr):
	cs = yr % ns - 1
	nt = yr % nt - 1
	return s[cs] + t[nt]
(ns, nt) = map(int, input().split())
s = list(input().split())
t = list(input().split())
q = int(input())
for _ in range(q):
	yr = int(input())
	print(solve(s, t, ns, nt, yr))


(n, m) = map(int, input().split())
n1 = list(input().split())
m1 = list(input().split())
t = int(input())
for i in range(t):
	i = int(input())
	x = n1[i % n - 1]
	y = m1[i % m - 1]
	z = [x, y]
	print(''.join(z))


inp = input().split(' ')
symbols = [input().split(' ') for i in range(2)]
n = int(input())
inputs = [int(input()) for i in range(n)]
res = []
for i in range(len(inputs)):
	res.append(symbols[0][inputs[i] % len(symbols[0]) - 1] + symbols[1][inputs[i] % len(symbols[1]) - 1])
print('\n'.join(res))


l = list(map(int, input().split()))
n = l[0]
m = l[1]
s = []
t = []
s1 = input()
s = s1.split(' ')
t1 = input()
t = t1.split(' ')
q = int(input())
z = 0
for i in range(q):
	z = int(input()) - 1
	str = s[z % len(s)] + t[z % len(t)]
	print(str)


(n, m) = map(int, input().split())
l1 = [str(j) for j in input().split()][:n]
l2 = [str(j) for j in input().split()][:m]
for i in range(int(input())):
	a = int(input())
	b = a % n
	c = a % m
	print(l1[b - 1] + l2[c - 1])


(n, m) = map(int, input().split())
p = input().split()
q = input().split()
for i in range(int(input())):
	y = int(input())
	print(p[y % n - 1] + q[y % m - 1])


from sys import stdin

def rl():
	return [int(w) for w in stdin.readline().split()]
(n, m) = rl()
s = stdin.readline().split()
t = stdin.readline().split()
(q,) = rl()
for _ in range(q):
	(y,) = rl()
	print(s[(y - 1) % n] + t[(y - 1) % m])


list = []
(n, m) = map(int, input().split())
a = input().split()
b = input().split()
t = int(input())
for test_case in range(t):
	y = int(input())
	j = y % n
	k = y % m
	list.append(a[j - 1] + b[k - 1])
for items in list:
	print(items)


(n, m) = map(int, input().split(' '))
n_str_list = input().split(' ')
m_str_list = input().split(' ')
q = int(input())
for _ in range(q):
	y = int(input())
	name = n_str_list[y % n - 1] + m_str_list[y % m - 1]
	print(name)


(s1, s2) = (int(x) for x in input().split(' '))
s1_array = input().split(' ')
s2_array = input().split(' ')
T = int(input())
for test in range(T):
	rank = int(input()) - 1
	s1_string = s1_array[rank % s1]
	s2_string = s2_array[rank % s2]
	print(s1_string + s2_string)


(n, m) = map(int, input().split())
s = input().split()
t = input().split()
q = int(input())
for w in range(q):
	y = int(input()) - 1
	print(s[y % n] + t[y % m])


(n, m) = map(int, input().split())
first = list(input().split())
second = list(input().split())
t = int(input())
for i in range(t):
	x = int(input()) - 1
	print(first[x % n] + second[x % m])


(n, m) = input().split()
n = int(n)
m = int(m)
na = input().split(' ')
ma = input().split(' ')
q = int(input())
for i in range(0, q):
	x = int(input()) - 1
	print(f'{na[x % n]}{ma[x % m]}')


import sys
it = iter(sys.stdin.read().splitlines())
(n, m) = [int(x) for x in next(it).split()]
s1 = next(it).split()
s2 = next(it).split()
q = int(next(it))
for i in range(q):
	year = int(next(it))
	p1 = year % n
	p2 = year % m
	print(s1[p1 - 1] + s2[p2 - 1])


(n, m) = map(int, input().split())
sa = input().split()
sb = input().split()
q = int(input())
for _ in range(q):
	a = int(input())
	print(sa[a % n - 1] + sb[a % m - 1])


def decision(input):
	iterstrings = iter(input.splitlines())
	(n, m) = map(int, next(iterstrings).split())
	sn = next(iterstrings).split()
	sm = next(iterstrings).split()
	q = next(iterstrings).split()
	years = map(int, iterstrings)

	def year_name(year):
		year -= 1
		return sn[year % n] + sm[year % m]
	answers = list(map(year_name, years))
	return '\n'.join(answers)
a = input()
if a:
	data = a
while a:
	try:
		a = input()
	except EOFError:
		break
	if a:
		data = data + '\n' + a
print(decision(data))


(n, m) = map(int, input().split())
a = list(map(str, input().strip().split()))[:n]
b = list(map(str, input().strip().split()))[:m]
q = int(input())
for i in range(q):
	year = int(input())
	x = year % n
	y = year % m
	print(a[x - 1] + b[y - 1])


denote = input().split(' ')
a = input().split(' ')
b = input().split(' ')
times = int(input())
l_ist = []
for x in range(times):
	l_ist.append(int(input()))
for x in l_ist:
	c = int(x) % int(denote[0])
	d = int(x) % int(denote[1])
	print(a[c - 1] + b[d - 1])


(n, m) = map(int, input().split())
a = list(map(str, input().split()))
b = list(map(str, input().split()))
q = int(input())
lena = len(a)
lenb = len(b)
for i in range(q):
	x = int(input())
	print(a[(x - 1) % lena] + b[(x - 1) % lenb])


a = list(map(int, input().split()))
m = a[0]
n = a[1]
s = input().split()
t = input().split()
q = int(input())
y = []
result = []
for i in range(q):
	y.append(int(input()))
for i in y:
	if i % m == 0 and i % n == 0:
		result.append(s[m - 1] + t[n - 1])
	elif i % m == 0:
		result.append(s[m - 1] + t[i % n - 1])
	elif i % n == 0:
		result.append(s[i % m - 1] + t[n - 1])
	else:
		result.append(s[i % m - 1] + t[i % n - 1])
for i in range(q):
	print(result[i])


try:
	(n, m) = map(int, input().split())
	s = list(map(str, input().split()))
	t = list(map(str, input().split()))
	q = int(input())
	l = []
	for _ in range(q):
		l.append(int(input()))
	for i in range(q):
		if l[i] > n and l[i] > m:
			print(s[l[i] % n - 1] + t[l[i] % m - 1])
		elif l[i] > n and l[i] <= m:
			print(s[l[i] % n - 1] + t[l[i] - 1])
		elif l[i] <= n and l[i] > m:
			print(s[l[i] - 1] + t[l[i] % m - 1])
		else:
			print(s[l[i] - 1] + t[l[i] - 1])
except:
	pass


(n, m) = input().split()
n = int(n)
m = int(m)
s = list(input().split())
t = list(input().split())
q = int(input())
for i in range(q):
	n = int(input())
	ind1 = 0
	ind2 = 0
	if n % len(s) == 0:
		ind1 = len(s)
	else:
		ind1 = n % len(s)
	if n % len(t) == 0:
		ind2 = len(t)
	else:
		ind2 = n % len(t)
	ans = s[ind1 - 1] + t[ind2 - 1]
	print(ans)


(n, m) = map(int, input().split())
s = tuple(input().split())
t = tuple(input().split())
for i in range(int(input())):
	p = int(input())
	print(s[p % n - 1] + t[p % m - 1])


(n, m) = list(map(int, input().split()))
strs1 = input().split()
strs2 = input().split()
for _ in range(int(input())):
	x = int(input())
	x -= 1
	print(strs1[x % n] + strs2[x % m])


(n, m) = map(int, input().split())
mas1 = list(map(str, input().split()))
mas2 = list(map(str, input().split()))
q = int(input())
for i in range(q):
	a = int(input())
	a -= 1
	a %= n * m
	x = 0
	y = 0
	for j in range(a):
		x += 1
		y += 1
		if x == n:
			x = 0
		if y == m:
			y = 0
	print(mas1[x] + mas2[y])


import sys
(n, m) = [int(e) for e in sys.stdin.readline().split()]
S = [e for e in sys.stdin.readline().split()]
T = [e for e in sys.stdin.readline().split()]
q = int(sys.stdin.readline())
for _ in range(q):
	y = int(sys.stdin.readline())
	sout = S[(y - 1) % n] + T[(y - 1) % m]
	print(sout)


(n, m) = map(int, input().split())
(a, s) = (input().split(), input().split())
for _ in range(int(input())):
	x = int(input())
	x -= 1
	print(a[x % n] + s[x % m])


def num():
	return int(input())

def line():
	return map(int, input().split())
from itertools import repeat
(n, m) = line()
s = input().split()
t = input().split()
q = num()
for _ in repeat(None, q):
	y = num()
	y -= 1
	print(s[y % n] + t[y % m])


(n, m) = [int(i) for i in input().split()[:2]]
s1 = [str(j)[:10] for j in input().split()[:n]]
s2 = [str(k)[:10] for k in input().split()[:m]]
z = int(input())
f = 0
for i in range(z):
	a = int(input())
	if a <= n and a <= m:
		fans1 = a - 1
		fans2 = a - 1
		print(s1[fans1] + s2[fans2])
	elif a > n and a <= m:
		fans3 = a % n
		fans4 = a - 1
		print(s1[fans3 - 1] + s2[fans4])
	elif a <= n and a > m:
		fans5 = a - 1
		fans6 = a % m
		print(s1[fans5] + s2[fans6 - 1])
	elif a > n and a > m:
		ans1 = a % n
		ans2 = a % m
		print(s1[ans1 - 1] + s2[ans2 - 1])


(x, y) = map(int, input().split())
n = list(map(str, input().split()))
m = list(input().split())
a = int(input())
for i in range(a):
	year = int(input())
	if year % x != 0:
		x_name = n[year % x - 1]
	else:
		x_name = n[-1]
	if year != y:
		y_name = m[year % y - 1]
	else:
		y_name = m[-1]
	print(x_name + y_name)


(n, m) = map(int, input().split())
s_1 = input().split()
s_2 = input().split()
for _ in range(int(input())):
	t = int(input())
	print(s_1[t % n - 1] + s_2[t % m - 1])


(n, m) = list(map(int, input().split(' ')))
a = input().split(' ')
t = input().split(' ')
q = int(input())
for _ in range(q):
	year = int(input()) - 1
	print(a[year % n], t[year % m], sep='')


(n, m) = map(int, input().split())
li = list(input().split())
li1 = list(input().split())
j = int(input())
abc = ''
a = 0
b = 0
for i in range(j):
	k = int(input())
	a = k % n
	b = k % m
	print(li[a - 1] + li1[b - 1])


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
s = list(map(str, input().split()))
t = list(map(str, input().split()))
q = int(input())
for i in range(q):
	y = int(input())
	print(s[y % n - 1] + t[y % m - 1])


(n, m) = map(int, input().split())
s = [x for x in input().split()]
t = [e for e in input().split()]
for _ in range(int(input())):
	y = int(input()) - 1
	print(s[y % n] + t[y % m])


(n, m) = [int(s) for s in input().split()]
l1 = [s.strip() for s in input().split()]
l2 = [s.strip() for s in input().split()]
q = int(input())
for _ in range(q):
	y = int(input())
	print(l1[(y % n - 1) % n] + l2[(y % m - 1) % m])


def main():
	(n, m) = map(int, input().split(' '))
	l = list(map(str, input().split(' ')))
	r = list(map(str, input().split(' ')))
	for q in range(int(input())):
		y = int(input())
		temp = str()
		if y - 1 < n:
			temp = l[y - 1]
		else:
			temp = l[y % n - 1]
		if y - 1 < m:
			temp += r[y - 1]
		else:
			temp += r[y % m - 1]
		print(temp)
main()


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
input = lambda : sys.stdin.readline().rstrip()
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
(n, m) = map(int, input().split())
l1 = input().split(' ')
l2 = input().split(' ')
q = int(input())
for i in range(q):
	y = int(input())
	y -= 1
	print(l1[y % n] + l2[y % m])


(n, m) = map(int, input().split())
a = [i for i in input().split()]
b = [i for i in input().split()]
q = int(input())
s = ''
for i in range(q):
	x = int(input())
	if x % n == 0:
		s = a[n - 1]
	else:
		s = a[x % n - 1]
	if x % m == 0:
		s += b[m - 1]
	else:
		s += b[x % m - 1]
	print(s)


begin = input().split(' ')
n = int(begin[0])
m = int(begin[1])
sall = input()
s = sall.split(' ')
tall = input()
t = tall.split(' ')
q = int(input())
for i in range(0, q):
	y = int(input())
	print(s[(y - 1) % n] + t[(y - 1) % m])


(n, m) = [int(i) for i in input().split()]
arr1 = input().split(' ')
arr2 = input().split(' ')
num = int(input())
s = []
for z in range(num):
	year = int(input())
	s.append(arr1[year % n - 1] + arr2[year % m - 1])
for i in range(num):
	print(s[i])


import sys
(n, m) = map(int, input().split())
a = input().split()
b = input().split()
for _ in range(int(input())):
	y = int(input())
	y -= 1
	print(a[y % n] + b[y % m])


v = [int(x) for x in input().split()]
first = v[0]
second = v[1]
string1 = input().split()
string2 = input().split()
n = int(input())
for i in range(n):
	word = ''
	year = int(input())
	word += string1[year % first - 1]
	word += string2[year % second - 1]
	print(word)


nm = input()
nmSplit = nm.split()
n = int(nmSplit[0])
m = int(nmSplit[1])
readStrN = input()
nTokens = readStrN.split()
readStrM = input()
mTokens = readStrM.split()
q = int(input())
queries = []
for i in range(q):
	queries.append(int(input()))
for i in queries:
	print(nTokens[i % n - 1] + mTokens[i % m - 1])


input()
a = input().split(' ')
b = input().split(' ')
for i in range(int(input())):
	x = int(input()) - 1
	print(a[x % len(a)], b[x % len(b)], sep='')


(n, m) = map(int, input().split())
l1 = list(input().split())
l2 = list(input().split())
t = int(input())
for _ in range(t):
	x = int(input())
	if x % n == 0:
		print(l1[n - 1], end='')
	else:
		print(l1[x % n - 1], end='')
	if x % m == 0:
		print(l2[m - 1], end='')
	else:
		print(l2[x % m - 1], end='')
	print()


(n, m) = map(int, input().split())
S = map(str, input().split())
T = map(str, input().split())
s = list(S)
t = list(T)
q = int(input())
for i in range(q):
	y = int(input())
	s1 = s[y % n - 1]
	s2 = t[y % m - 1]
	print(s1 + s2)


(size1, size2) = map(int, input().split(' '))
s1 = input().split(' ')
s2 = input().split(' ')
no_of_years = int(input())
for i in range(no_of_years):
	year = int(input())
	n1 = year % size1
	n2 = year % size2
	print(s1[n1 - 1] + s2[n2 - 1])


(n, m) = list(map(int, input().strip().split()))
arr1 = list(input().split())
arr2 = list(input().split())
temp1 = 0
temp2 = 0
k = int(input().strip())
for i in range(k):
	queri = int(input().strip())
	temp1 = queri % n - 1
	temp2 = queri % m - 1
	ans = arr1[temp1] + arr2[temp2]
	print(ans)


(n, m) = list(map(int, input().split(' ')))
nl = [] + input().split(' ')
ml = [] + input().split(' ')
q = int(input())
while q > 0:
	q -= 1
	year = int(input())
	n_str = nl[year % len(nl) - 1]
	m_str = ml[year % len(ml) - 1]
	print(n_str + m_str)


(n, m) = list(map(int, input().split()))
s = list(input().split())
t = list(input().split())
q = int(input())
for Q in range(q):
	y = int(input())
	print(s[(y - 1) % n] + t[(y - 1) % m])


(n, m) = tuple(map(int, input().split()))
s = list()
t = list()
s = input().split()
t = input().split()
num = int(input())
for i in range(num):
	inp = int(input())
	print(s[inp % n - 1] + t[inp % m - 1])


data = input().split()
n = int(data[0])
m = int(data[1])
arr_n = input().split()
arr_m = input().split()
q = int(input())
for i in range(q):
	y = int(input()) - 1
	print(arr_n[y % n] + arr_m[y % m])


def main():
	(n, m) = tuple([int(num) for num in input().split()])
	s = input().split()
	t = input().split()
	i = int(input())
	for _ in range(i):
		year = int(input())
		year_str = s[year % n - 1] + t[year % m - 1]
		print(year_str)
main()


(n, m) = list(map(int, input().split()))
x = input().split()
y = input().split()
T = int(input())
for i in range(T):
	year = int(input())
	fir = year % n
	sec = year % m
	print(x[fir - 1] + y[sec - 1])


(n, m) = map(int, input().split())
ls = list(input().split())
lt = list(input().split())
q = int(input())
for i in range(q):
	y = int(input())
	if y >= n:
		g = y % n
		a = ls[g - 1]
	else:
		g = y
		a = ls[g - 1]
	if y >= m:
		g = y % m
		b = lt[g - 1]
	else:
		g = y
		b = lt[g - 1]
	print(a + b)


(n, m1) = map(int, input().split())
a = list(map(str, input().split()))
b = list(map(str, input().split()))
k = int(input())
for i in range(k):
	i1 = int(input())
	print(a[i1 % n - 1] + b[i1 % m1 - 1])


def solution(query, s, t, n, m):
	i1 = query % n - 1
	i2 = query % m - 1
	s = s.split(' ')
	t = t.split(' ')
	print(f'{s[i1]}{t[i2]}')
(n, m) = [int(x) for x in input().split()]
s = input()
t = input()
q = int(input())
for _ in range(q):
	query = int(input())
	solution(query, s, t, n, m)


(n, m) = input().split()
(n, m) = (int(n), int(m))
s = list(map(str, input().split()))[:n]
t = list(map(str, input().split()))[:m]
q = int(input())
quer = []
for i in range(q):
	num = int(input())
	quer.append(num)
for i in quer:
	if i <= n and i <= m:
		print(s[i - 1] + t[i - 1])
	elif i > n and i <= m:
		str1 = t[i - 1]
		while i > n:
			i = i % n
		print(s[i - 1] + str1)
	elif i <= n and i > m:
		str1 = s[i - 1]
		while i > m:
			i = i % m
		print(str1 + t[i - 1])
	elif i > n and i > m:
		(num1, num2) = (i, i)
		while num1 > n:
			num1 = num1 % n
		while num2 > m:
			num2 = num2 % m
		print(s[num1 - 1] + t[num2 - 1])


NM = input()
NM = NM.split(' ')
N = int(NM[0])
M = int(NM[1])
f = input()
s = input()
ff = f.split(' ')
ss = s.split(' ')
Q = int(input())
for _ in range(Q):
	qq = int(input())
	y = ff[qq % N - 1] + ss[qq % M - 1]
	print(y)


(n, m) = map(int, input().split())
s = [x for x in input().split()]
t = [x for x in input().split()]
q = int(input())
for _ in range(q):
	y = int(input())
	if y == n:
		r1 = n
	else:
		r1 = y % n
	if y == m:
		r2 = m
	else:
		r2 = y % m
	print(s[r1 - 1] + t[r2 - 1])


(n, m) = map(int, input().split())
arr = list(map(str, input().split()))
brr = list(map(str, input().split()))
for _ in range(int(input())):
	x = int(input())
	fi = x % n
	se = x % m
	if fi == 0 and se == 0:
		print(arr[-1] + brr[-1])
	else:
		print(arr[fi - 1] + brr[se - 1])


(n, m) = map(int, input().split(' '))
s = list(input().split(' '))
t = list(input().split(' '))
q = int(input())
for _ in range(q):
	x = int(input())
	if x <= n:
		s1 = s[x - 1]
	else:
		a = x % n
		s1 = s[a - 1]
	if x <= m:
		t1 = t[x - 1]
	else:
		b = x % m
		t1 = t[b - 1]
	print(s1 + t1)


def main():
	(n, m) = input().split()
	s1 = input().split()
	s2 = input().split()
	q = int(input())
	for i in range(q):
		a = int(input())
		print(s1[a % int(n) - 1] + s2[a % int(m) - 1])
main()


(n, m) = map(int, input().split())
s = list(map(str, input().split()))
t = list(map(str, input().split()))
q = int(input())
y = []
for i in range(q):
	y.append(int(input()))
for i in range(0, q):
	if y[i] > n:
		ni = y[i] % n - 1
	else:
		ni = y[i] - 1
	if y[i] > m:
		mi = y[i] % m - 1
	else:
		mi = y[i] - 1
	print(s[ni] + t[mi])


S = input()
L = S.split()
n = int(L[0])
m = int(L[1])
S = input()
A = S.split()
T = input()
B = T.split()
q = int(input())
for i in range(q):
	y = int(input())
	print(A[y % n - 1], B[y % m - 1], sep='')


(n, m) = map(int, input().split())
l = list(map(str, input().split()))
p = list(map(str, input().split()))
a = int(input())
for i in range(a):
	b = int(input())
	print(l[b % n - 1] + p[b % m - 1])


(n, m) = list(map(int, input().split()))
s1 = input().split()
s2 = input().split()
q = int(input())
for _ in range(q):
	y = int(input())
	(p, q) = (y % n, y % m)
	print(s1[p - 1] + s2[q - 1])


(n, m) = map(int, input().split())
a = [0] + list(input().split())
b = [0] + list(input().split())
q = int(input())
for _ in range(q):
	temp = int(input())
	t1 = temp % n
	t2 = temp % m
	if t1 == 0:
		t1 = n
	if t2 == 0:
		t2 = m
	res = a[t1] + b[t2]
	print(res)


(n, m) = [int(x) for x in input().split()]
s = [x for x in input().split()]
t = [x for x in input().split()]
q = int(input())
while q != 0:
	q -= 1
	y = int(input())
	i = y % n
	j = y % m
	if i == 0:
		i = n
	if j == 0:
		j = m
	print(s[i - 1] + t[j - 1])


(n, m) = map(int, input().split())
s1 = list(input().split())
s2 = list(input().split())
for _ in range(int(input())):
	q = int(input())
	q1 = q % n
	q2 = q % m
	if q1 == 0:
		q1 = n
	if q2 == 0:
		q2 = m
	print(s1[q1 - 1] + s2[q2 - 1])


import sys
(n, m) = [int(i) for i in input().split()]
s1 = input().strip().split()
s2 = input().strip().split()
q = int(input())
for i in range(q):
	y = int(input()) - 1
	print(s1[y % n] + s2[y % m])


(n, m) = input().split(' ')
result = ''
word_1 = input().split(' ')
word_2 = input().split(' ')
num = int(input().strip())
for i in range(num):
	year = int(input().strip())
	if year <= int(n) and year <= int(m):
		result = word_1[year - 1] + word_2[year - 1]
	elif year <= int(n) and year > int(m):
		result = word_1[year - 1] + word_2[year - year // int(m) * int(m) - 1]
	elif year > int(n) and year <= int(m):
		result = word_1[year - year // int(n) * int(n) - 1] + word_2[year - 1]
	else:
		result = word_1[year - year // int(n) * int(n) - 1] + word_2[year - year // int(m) * int(m) - 1]
	print(result)


l = input().split(' ')
n = int(l[0])
m = int(l[1])
s1 = input().split(' ')
s2 = input().split(' ')
q = int(input())
for i in range(q):
	w = int(input())
	n1 = w % n
	n2 = w % m
	s = ''
	s = s1[n1 - 1] + s2[n2 - 1]
	print(s)


from bisect import *
from collections import *
from itertools import *
import functools
import sys
import math
from decimal import *
from copy import *
from heapq import *
from fractions import *
getcontext().prec = 30
MAX = sys.maxsize
MAXN = 1000010
MOD = 10 ** 9 + 7
spf = [i for i in range(MAXN)]

def sieve():
	for i in range(2, MAXN, 2):
		spf[i] = 2
	for i in range(3, int(MAXN ** 0.5) + 1):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def fib(n, m):
	if n == 0:
		return [0, 1]
	else:
		(a, b) = fib(n // 2)
		c = a % m * (b % m * 2 - a % m) % m
		d = a % m * (a % m) % m + b % m * b % m % m
		if n % 2 == 0:
			return [c, d]
		else:
			return [d, c + d]

def charIN(x=' '):
	return sys.stdin.readline().strip().split(x)

def arrIN(x=' '):
	return list(map(int, sys.stdin.readline().strip().split(x)))

def ncr(n, r):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % MOD
		den = den * (i + 1) % MOD
	return num * pow(den, MOD - 2, MOD) % MOD

def flush():
	return sys.stdout.flush()
(n, m) = arrIN()
s = charIN()
t = charIN()
temp = [s[0] + t[0]]
if not (n == 1 and m == 1):
	i = j = 0
	i += 1
	i %= n
	j += 1
	j %= m
	while not (i == 0 and j == 0):
		temp.append(s[i] + t[j])
		i += 1
		j += 1
		i %= n
		j %= m
l = len(temp)
for _ in range(int(input())):
	x = int(input())
	x %= l
	x -= 1
	print(temp[x])


def lcm(x, y):
	if x > y:
		z = x
	else:
		z = y
	while True:
		if z % x == 0 and z % y == 0:
			lcm = z
			break
		z += 1
	return lcm
t = input()
t = t.split(' ')
t = [int(x) for x in t]
n = t[0]
m = t[1]
lcm = lcm(n, m)
ns = input()
ns = ns.split(' ')
ms = input()
ms = ms.split(' ')
q = int(input())
lst = []
for i in range(q):
	d = int(input())
	lst.append(d)
for i in lst:
	a = i % lcm
	print(ns[a % n - 1] + ms[a % m - 1])


t = 1
while t > 0:
	(n, m) = map(int, input().split())
	an = input().split()
	am = input().split()
	ans = []
	q = int(input())
	while q:
		qi = int(input()) - 1
		print(an[qi % n] + am[qi % m])
		q -= 1
	t -= 1


(n, m) = map(int, input().split())
nStrings = input().split()
mStrings = input().split()
t = int(input())
for _ in range(t):
	k = int(input())
	print(nStrings[(k - 1) % n] + mStrings[(k - 1) % m])


a = input()
lst1 = input().split()
lst2 = input().split()
n = int(input())
for i in range(n):
	year = int(input())
	firstindex = year % len(lst1)
	if firstindex != 0:
		first = lst1[firstindex - 1]
	else:
		first = lst1[-1]
	secondIndex = year % len(lst2)
	if secondIndex != 0:
		second = lst2[secondIndex - 1]
	else:
		second = lst2[-1]
	print(first + second)


(n, m) = [int(x) for x in input().split()]
first = input().split()
second = input().split()
q = int(input())
for i in range(q):
	year = int(input())
	delta1 = (year - 1) % n
	delta2 = (year - 1) % m
	ans = ''
	ans += first[delta1]
	ans += second[delta2]
	print(ans)


(n, m) = map(int, input().split())
li1 = list(input().split())
li2 = list(input().split())
q = int(input())
y = [int(input()) for i in range(q)]
for i in range(q):
	ans = ''
	ans += li1[y[i] % n - 1]
	ans += li2[y[i] % m - 1]
	print(ans)


(a, b) = tuple(input().split())
n = list(input().split())
m = list(input().split())
l = []
for i in range(int(input())):
	e = int(input())
	k = e % int(a)
	q = e % int(b)
	if k == 0:
		k = int(a)
	if q == 0:
		q = int(b)
	print(n[k - 1] + m[q - 1])


(n, m) = [int(x) for x in input().split()]
S = input().split()
T = input().split()
q = int(input())
for query in range(q):
	year = int(input()) - 1
	print(str(S[year % n]) + str(T[year % m]))


l = [int(x) for x in input().split()]
n = l[0]
m = l[1]
l.clear()
s1 = input().split()
s2 = input().split()
q = int(input())
for i in range(q):
	y = int(input())
	print(s1[(y - 1) % n] + s2[(y - 1) % m])


(n, m) = list(map(int, input().split()))
s = list(input().split())
t = list(input().split())
q = int(input())
for a_ in range(q):
	year = int(input())
	if year < n:
		a = year - 1
	else:
		a = year % n - 1
	if year < m:
		b = year - 1
	else:
		b = year % m - 1
	st1 = s[a]
	st2 = t[b]
	print(st1 + st2)


(a, b) = input().split()
(a, b) = (int(a), int(b))
s = input().split()
t = input().split()
q = int(input())
for i in range(q):
	d = int(input())
	sd = s[d % a - 1]
	td = t[d % b - 1]
	print(sd + td)


(n, m) = map(int, input().split())
str1 = input().split()
str2 = input().split()
len1 = len(str1)
len2 = len(str2)
q = int(input())
for _ in range(q):
	year = int(input())
	final_str = str1[(year - 1) % len1] + str2[(year - 1) % len2]
	print(final_str)


(n, m) = map(int, input().split())
n_strings = list(input().split())
m_strings = list(input().split())
q = int(input())
for i in range(q):
	y = int(input())
	print(n_strings[(y - 1) % n] + m_strings[(y - 1) % m])


def naming(s1, s2, year):
	idx1 = idx2 = 0
	idx1 = year % len(s1)
	idx2 = year % len(s2)
	print(s1[idx1 - 1] + s2[idx2 - 1])

def main():
	input()
	s1 = input().split(' ')
	s2 = input().split(' ')
	y = int(input())
	for i in range(y):
		year = int(input())
		naming(s1, s2, year)
main()


(n, m) = [int(ele) for ele in input().split()]
l1 = [ele for ele in input().split()]
l2 = [ele for ele in input().split()]
q = int(input())
while q > 0:
	num = int(input())
	i = num % n
	j = num % m
	p = l1[i - 1]
	r = l2[j - 1]
	res = p + r
	print(res)
	q -= 1


import sys
(n, m) = list(map(int, sys.stdin.readline().strip().split()))
a = list(sys.stdin.readline().strip().split())
b = list(sys.stdin.readline().strip().split())
q = int(input())
for i in range(q):
	x = int(input())
	x = x - 1
	print(a[x % n] + b[x % m])


(n, m) = map(int, input().split())
ln = [i for i in input().split()]
lm = [i for i in input().split()]
q = int(input())
qlst = [int(input()) for i in range(q)]
for i in qlst:
	if i % n == 0:
		res = '' + ln[n - 1]
	else:
		res = '' + ln[i % n - 1]
	if i % m == 0:
		res += lm[m - 1]
	else:
		res += lm[i % m - 1]
	print(res)


(n, m) = input().split(' ')
n = int(n)
m = int(m)
S = list(map(str, input().split(' ')))
T = list(map(str, input().split(' ')))
q = int(input())
while q > 0:
	y = int(input())
	f = y % n
	se = y % m
	e = S[f - 1]
	e1 = T[se - 1]
	d = e + e1
	print(d)
	q = q - 1


a = input()
a = a.split(' ')
n = a[0]
m = a[1]
n = int(n)
m = int(m)
s = input()
s = s.split(' ')
t = input()
t = t.split(' ')
q = input()
q = int(q)
ans = []
for i in range(q):
	r = int(input())
	r2 = r % n
	r3 = r % m
	res = s[r2 - 1] + t[r3 - 1]
	ans.append(res)
for i in ans:
	print(i)


s1 = []
s2 = []
s3 = []
(n, m) = map(int, input().split())
inp = input()
for i in inp.split():
	s1.append(i)
inp2 = input()
for i in inp2.split():
	s2.append(i)
q = int(input())
for i in range(q):
	a = int(input())
	s3.append(s1[(a - 1) % n] + s2[(a - 1) % m])
for i in s3:
	print(i)


(m, n) = map(int, str(input()).split())
l = [x for x in str(input()).split()]
a = [x for x in str(input()).split()]
q = int(input())
for z in range(q):
	x = int(input())
	x1 = x % m
	x2 = x % n
	if x1 == 0:
		x1 = m
	if x2 == 0:
		x2 == n
	s = l[x1 - 1] + a[x2 - 1]
	print(s)


t = 1
for i in range(0, 1):
	(n, m) = map(int, input().split())
	arr1 = input().split(' ')
	arr2 = input().split(' ')
	q = int(input())
	for i in range(0, q):
		y = int(input())
		c1 = (y - 1) % n
		c2 = (y - 1) % m
		w = arr1[c1] + arr2[c2]
		print(w)


L = input().split(' ')
N = int(L[0])
M = int(L[1])
s1 = input().split(' ')
s2 = input().split(' ')
n = int(input())
while n != 0:
	n -= 1
	ans1 = ''
	ans2 = ''
	y = int(input())
	ans1 = s1[y % N - 1]
	ans2 = s2[y % M - 1]
	print(ans1 + ans2)


(n, m) = map(int, input().split())
a = list(map(str, input().split()))
b = list(map(str, input().split()))
total = n * m
c = [''] * (n * m)
for i in range(n * m):
	c[i] = a[i % n] + b[i % m]
for _ in range(int(input())):
	x = int(input())
	print(c[(x - 1) % (n * m)])


(n, m) = [int(x) for x in input().split()]
m_list = n_list = []
n_list = [x for x in input().split()]
m_list = [x for x in input().split()]
q = int(input())
q_list = []
for i in range(1, q + 1):
	q_list.append(int(input()))
for i in q_list:
	n_ind = i % n
	m_ind = i % m
	if n_ind == 0:
		n_val = n_list[n - 1]
	else:
		n_val = n_list[n_ind - 1]
	if m_ind == 0:
		m_val = m_list[m - 1]
	else:
		m_val = m_list[m_ind - 1]
	print(n_val + m_val)


(n, m) = map(int, input().split())
s = input().split()
t = input().split()
tests = int(input())
for i in range(tests):
	num = int(input())
	print(s[(num - 1) % n] + t[(num - 1) % m])


(a, b) = map(int, input().split())
c = list(input().split())
d = list(input().split())
for x in range(int(input())):
	n = int(input())
	print(c[n % a - 1] + d[n % b - 1])


(n, m) = map(int, input().split())
s_strings = input().split()
t_strings = input().split()
q = int(input())
for _ in range(q):
	year = int(input())
	s_index = year % n - 1
	t_index = year % m - 1
	print(s_strings[s_index] + t_strings[t_index])


import sys

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())

def solve():
	(n, m) = mints()
	s = minp().split()
	t = minp().split()
	for i in range(mint()):
		y = mint() - 1
		print(s[y % n] + t[y % m])
solve()


(x, y) = (int(v) for v in input().split())
n = [p for p in input().split()]
m = [q for q in input().split()]
case = int(input())
for i in range(case):
	year = int(input())
	print(n[year % x - 1] + m[year % y - 1])


(n, m) = map(int, input().split())
list1 = list(map(str, input().split()))
list2 = list(map(str, input().split()))
q = int(input())
list3 = []
for i in range(q):
	list3.append(int(input()))
for j in list3:
	x = j % n
	y = j % m
	if x == 0:
		d = list1[n - 1]
	else:
		d = list1[x - 1]
	if y == 0:
		d += list2[m - 1]
	else:
		d += list2[y - 1]
	print(d)


x = input().split()
n = int(x[0])
m = int(x[1])
s = input().split()
t = input().split()
for i in range(int(input())):
	yr = int(input())
	p_1 = yr % n
	p_2 = yr % m
	ans = s[p_1 - 1] + t[p_2 - 1]
	print(ans)


number = list(map(int, input().split()))
s = list(map(str, input().split()))
t = list(map(str, input().split()))
list = []
for index in range(int(input())):
	list.append(int(input()))
for index in list:
	print(s[(index - 1) % number[0]] + t[(index - 1) % number[1]])


(n, m) = map(int, input().split())
l1 = list(input().split())
l2 = list(input().split())
for i in range(int(input())):
	x = int(input())
	print(l1[x % n - 1] + l2[x % m - 1])


from sys import stdin
inp = stdin.readline
(n, m) = [int(k) for k in inp().strip().split()]
s = inp().strip().split()
t = inp().strip().split()
q = int(inp().strip())
while q:
	q -= 1
	y = int(inp().strip()) - 1
	print(s[y % n], t[y % m], sep='')


(n, m) = [int(x) for x in input().split()]
s = [str(x) for x in input().split()]
t = [str(x) for x in input().split()]
q = int(input())
a = []
for i in range(0, q):
	a.append(int(input()))
for i in range(0, q):
	print(s[a[i] % n - 1] + t[a[i] % m - 1])