The defaultdict tool is a container in the collections class of Python. It's similar to the usual dictionary (dict) container, but the only difference is that a defaultdict will have a default value if that key has not been set yet. If you didn't use a defaultdict you'd have to check to see if that key exists, and if it doesn't, set it to what you want. 

For example:

from collections import defaultdict
d = defaultdict(list)
d['python'].append("awesome")
d['something-else'].append("not relevant")
d['python'].append("language")
for i in d.items():
    print i

This prints:

('python', ['awesome', 'language'])
('something-else', ['not relevant'])

In this challenge, you will be given $2$ integers, $n$ and $m$. There are $n$ words, which might repeat, in word group $\mbox{A}$. There are $m$ words belonging to word group $\mbox{B}$. For each  $m$ words, check whether the word has appeared in group $\mbox{A}$ or not. Print the indices of each occurrence of $m$ in group $\mbox{A}$. If it does not appear, print $-1$.

Example  

Group A contains 'a', 'b', 'a'
Group B contains 'a', 'c'

For the first word in group B, 'a', it appears at positions $\mbox{I}$ and $3$ in group A.
The second word, 'c', does not appear in group A, so print $-1$.

Expected output:

1 3
-1

Input Format

The first line contains integers, $n$ and $m$ separated by a space. 

The next $n$ lines contains the words belonging to group $\mbox{A}$. 

The next $m$ lines contains the words belonging to group $\mbox{B}$.

Constraints

$1\leq n\leq10000$ 

$1\leq m\leq100$ 

$1\leq\textit{length of each word in the input}\leq100$

Output Format

Output $m$ lines. 

The $i^{\mbox{th}}$ line should contain the $\mbox{I}$-indexed positions of the occurrences of the $i^{\mbox{th}}$ word separated by spaces. 

Sample Input
STDIN   Function
-----   --------
5 2     group A size n = 5, group B size m = 2
a       group A contains 'a', 'a', 'b', 'a', 'b'
a
b
a
b
a       group B contains 'a', 'b'
b

Sample Output
1 2 4
3 5

Explanation

'a' appeared $3$ times in positions $\mbox{I}$, $2$ and $\begin{array}{c}A\end{array}$. 

 'b' appeared $2$ times in positions $3$ and $5$. 

In the sample problem, if 'c' also appeared in word group $\mbox{B}$, you would print $-1$.

Difficulty: EASY

Solutions:
from collections import defaultdict as dd
(n, m) = map(int, input().split())
A = dd(list)
for i in range(n):
	A[input()].append(str(i + 1))
for _ in range(m):
	word = input()
	if word in A:
		print(' '.join(A[word]))
	else:
		print(-1)


from collections import defaultdict
d = defaultdict(list)
(n, m) = map(int, input().split())
d['A'] = [input() for _ in range(n)]
d['B'] = [input() for _ in range(m)]
for k in d['B']:
	l = []
	for (i, j) in enumerate(d['A']):
		if k == j:
			l.append(i + 1)
	if l != []:
		print(' '.join(map(str, l)))
	else:
		print(-1)


from collections import defaultdict
[n, m] = [int(i) for i in input().split(' ')]
A = defaultdict(list)
for j in range(n):
	A[input()].append(str(j + 1))
for i in range(m):
	xinput = input()
	if xinput in A.keys():
		print(' '.join(A[xinput]))
	else:
		print('-1')


from collections import defaultdict
(n, m) = map(int, input().split())
dic = defaultdict(list)
for (idx, val) in enumerate(range(0, n)):
	letter = input()
	dic[letter].append(idx + 1)
for _ in range(0, m):
	letter = input()
	if not dic[letter]:
		print('-1')
	else:
		print(' '.join(map(str, dic[letter])))


from collections import defaultdict
d = defaultdict(list)
(n, m) = (int(x) for x in input().split())
for index in range(n):
	word = input()
	d[word].append(str(index + 1))
for _ in range(m):
	word = input()
	if word in d:
		print(' '.join(d[word]))
	else:
		print(-1)


from collections import defaultdict
d = defaultdict(list)
(n, m) = [int(i) for i in input().split(' ')]
for i in range(1, n + 1):
	x = input()
	d[x].append(i)
for i in range(m):
	x = input()
	if x not in d:
		print(-1)
	else:
		print(' '.join(map(str, d[x])))


from collections import defaultdict
d = defaultdict(list)
k = input().strip()
n = int(k.split(' ')[0])
m = int(k.split(' ')[1])
for i in range(0, n):
	c = input().strip()
	d[c].append(i + 1)
for i in range(0, m):
	c = input().strip()
	for j in range(0, len(d[c]) - 1):
		print(d[c][j], end=' ')
	if len(d[c]) > 0:
		print(d[c][len(d[c]) - 1], end='')
	else:
		print(-1, end='')
	print()


lin = input().strip().split()
(nnum, mnum) = (int(lin[0]), int(lin[1]))
n = []
for num in range(nnum):
	n.append(input())
m = []
for num in range(mnum):
	m.append(input())
	if n.count(m[num]) > 0:
		print(' '.join((str(s) for s in [i + 1 for (i, x) in enumerate(n) if x == m[num]])))
	else:
		print(-1)


from collections import defaultdict
(n, m) = input().split()
listA = []
for i in range(0, int(n)):
	listA.append(input())
dictB = defaultdict(list)
checkKeys = []
for i in range(0, int(m)):
	key = input()
	dictB[key] = []
	checkKeys.append(key)
notfound = defaultdict(int)
for i in range(0, int(n)):
	if listA[i] in dictB:
		dictB[listA[i]].append(str(i + 1))
for key in checkKeys:
	if len(dictB[key]) > 0:
		strB = ' '.join(dictB[key])
		print(strB)
	else:
		print('-1')


from collections import defaultdict

def main():
	d = defaultdict(list)
	(n, m) = tuple(map(int, input().strip().split()))
	for i in range(n):
		d['A'].append(input().strip())
	for i in range(m):
		d['B'].append(input().strip())
	for word in d['B']:
		r = [i + 1 for (i, j) in enumerate(d['A']) if j == word]
		if r != []:
			r = str(r)
			print(r[1:-1].replace(',', ''))
		else:
			print('-1')
main()


Bounds = list((int(i) for i in input().split()))
Words = []
toFind = []
for i in range(0, Bounds[0]):
	Words.append(str(input()))
for i in range(0, Bounds[1]):
	toFind.append(str(input()))
for i in range(0, len(toFind)):
	temp = ''
	for x in range(0, len(Words)):
		if Words[x] == toFind[i]:
			temp += str(x + 1) + ' '
	if temp == '':
		print('-1')
	else:
		print(temp.strip())


from collections import defaultdict
(n, m) = map(int, input().split())
xs = defaultdict(list)
for i in range(n):
	xs[input()].append(i + 1)
ys = [input() for _ in range(m)]
for ch in ys:
	if ch not in xs:
		print(-1)
	else:
		print(*xs[ch])


from collections import defaultdict
c = input().split(' ')
n = int(c[0])
m = int(c[1])
d = defaultdict(list)
for i in range(0, n):
	d[input()].append(i + 1)
for _ in range(0, m):
	temp = input()
	if d.__contains__(temp):
		print(' '.join(map(str, d.get(temp))))
	else:
		print(-1)


from collections import defaultdict
words = defaultdict(list)
(n, m) = map(int, input().split())
for i in range(n):
	words[input()].append(str(i + 1))
for i in range(m):
	word = input()
	if word in words:
		print(' '.join(words[word]))
	else:
		print('-1')


from collections import defaultdict
d = defaultdict(list)
(n, m) = input().split(' ')
for i in range(0, int(n)):
	d[input()].append(str(i + 1))
for i in range(0, int(m)):
	t = d[input()]
	if len(t) == 0:
		print('-1')
	else:
		print(' '.join(t))


(n, m) = map(int, input().split(' '))
a = {}
b = []
for index in range(n):
	word = input()
	try:
		a[word].append(index + 1)
	except KeyError:
		a[word] = [index + 1]
for index in range(m):
	b.append(input())
for word in b:
	if word in a:
		print(' '.join(map(str, a[word])))
	else:
		print(-1)


from collections import defaultdict
d = defaultdict(list)
(num, queries) = (int(x) for x in input().split())
for i in range(1, num + 1):
	d[input()].append(str(i))
for i in range(queries):
	query = str(input())
	if query in d:
		print(' '.join(d[query]))
	else:
		print(-1)


from collections import defaultdict
line = input().split()
n = int(line[0])
m = int(line[1])
d = defaultdict(list)
for i in range(1, n + 1):
	d[input()].append(str(i))
for i in range(m):
	word = input()
	if word in d:
		print(' '.join(d[word]))
	else:
		print(str(-1))


from collections import defaultdict
(n, m) = map(int, input().strip().split())
A = defaultdict(list)
for i in range(1, n + 1):
	A[input().strip()].append(i)
for i in range(m):
	b = input().strip()
	if len(A[b]) == 0:
		print('-1')
	else:
		print(' '.join((str(x) for x in A[b])))


from collections import defaultdict
d = defaultdict(list)
(n, m) = list(map(int, input().split()))
for i in range(n):
	w = input()
	d[w].append(str(i + 1))
for j in range(m):
	w = input()
	print(' '.join(d[w]) or -1)


from collections import defaultdict
(n, m) = list(map(int, input().split()))
A = defaultdict(list)
B = []
for x in range(1, n + 1):
	c = input()
	if c in A:
		A[c].append(str(x))
	else:
		A[c] = [str(x)]
for _ in range(m):
	B.append(input())
for c in B:
	if c in A:
		print(' '.join(A[c]))
	else:
		print(-1)


from collections import defaultdict
(n, m) = map(int, input().split())
d = defaultdict(list)
for i in range(n):
	d[input()].append(i + 1)
for i in range(m):
	q = input()
	if d[q]:
		print(*d[q])
	else:
		print(-1)


from collections import defaultdict
D = defaultdict(list)
(N, M) = tuple(map(int, input().split()))
for i in range(N):
	word = input()
	D[word].append(i + 1)
for _ in range(M):
	word = input()
	if word not in D:
		print(-1)
	else:
		print(' '.join(map(str, D[word])))


(n, m) = tuple(list(map(int, input().split(' '))))
data = [input() for _ in range(0, n)]
groups = [input() for _ in range(0, m)]
li = [[str(i + 1) for (i, e) in enumerate(data) if e == g] for g in groups]
for e in li:
	if len(e) == 0:
		print(-1)
	else:
		print(' '.join(e))


from collections import defaultdict
(n, m) = [int(i) for i in input().split()]
d = defaultdict(list)
k = 1
for j in range(n):
	a = input()
	d[a].append(str(k))
	k += 1
for l in range(m):
	b = input()
	if b in d:
		print(' '.join(d[b]))
	else:
		print(-1)


l = input().split()
m = int(l[0])
n = int(l[1])
d = []
for i in range(m):
	d.append(input())
k = []
for i in range(n):
	k.append(input())
for i in range(n):
	l = []
	s = ''
	for j in range(m):
		if k[i] == d[j]:
			l.append(j + 1)
	if len(l) == 0:
		s = '-1'
	else:
		s = ' '.join((str(e) for e in l))
	print(s)


from collections import defaultdict
(n, m) = map(int, input().split())
dd = defaultdict(list)
for i in range(n):
	dd[input()].append(i + 1)
for i in range(m):
	print(' '.join(map(str, dd.get(input(), [-1]))))


from collections import defaultdict
d = defaultdict(list)
(n, m) = tuple(map(int, input().split(' ')))
nwords = [input() for x in range(n)]
mwords = [input() for x in range(m)]
d['a'] = nwords
d['b'] = mwords

def indexes(word):
	return [x + 1 for x in range(len(nwords)) if nwords[x] == word]
for i in range(m):
	l = list(indexes(mwords[i]))
	if l != []:
		print(' '.join((str(x) for x in l)))
	else:
		print('-1')


from collections import defaultdict
d = defaultdict(list)
(n, m) = input().split()
(n, m) = (int(n), int(m))
for i in range(0, n):
	d[input()].append(str(i + 1))
for i in range(0, m):
	key = input()
	if key in d:
		print(' '.join(d.get(key)))
	else:
		print('-1')


import collections
(n, m) = map(int, input().split())
buckets = collections.defaultdict(list)
for i in range(1, n + 1):
	buckets[input()].append(str(i))
m_words = [input() for i in range(m)]
for word in m_words:
	positions = buckets.get(word)
	print(' '.join(positions) if positions else -1)


num = list(map(int, input().split()))
n = num[0]
m = num[1]
from collections import defaultdict
d = defaultdict(list)
for i in range(n):
	d['a'].append(input())
for i in range(m):
	d['b'].append(input())
for key in d['b']:
	tem = []
	for (i, j) in enumerate(d['a']):
		if key == j:
			tem.append(i + 1)
	if tem == []:
		print(-1)
	else:
		tem = map(str, tem)
		print(' '.join(tem))


from collections import defaultdict
(n, m) = map(int, input().split())
d = defaultdict(list)
for i in range(n):
	c = input()
	d[c].append(str(i + 1))
for i in range(m):
	c = input()
	if c not in d:
		print(-1)
	else:
		print(' '.join(d[c]))


from collections import defaultdict
d = defaultdict(list)
(n, m) = map(int, input().split())
for i in range(1, n + 1):
	s = input()
	d[s].append(i)
for j in range(0, m):
	s = input()
	if s in d.keys():
		print(' '.join(map(str, d[s])))
	else:
		print('-1')


from collections import defaultdict

def getRow(f=int):
	return [f(s) for s in input().split(' ')]
(T, V) = getRow()
data = defaultdict(list)
for i in range(0, T):
	data[getRow(str)[0]].append(i + 1)
keys = []
for i in range(0, V):
	keys.append(getRow(str)[0])
for k in keys:
	s = ' '.join([str(n) for n in data[k]])
	if s is '':
		s = '-1'
	print(s)


from collections import defaultdict
(n, m) = (int(i) for i in input().split(' '))
word_occurences = defaultdict(list)
for index in range(1, n + 1):
	word = input()
	word_occurences[word].append(index)
for _ in range(m):
	word = input()
	if word in word_occurences:
		indexes_as_strings = [str(index) for index in word_occurences[word]]
		print(' '.join(indexes_as_strings))
	else:
		print('-1')


from collections import defaultdict

def __starting_point():
	(n, m) = list(map(int, input().strip().split(' ')))
	library = defaultdict(list)
	for ind in range(1, n + 1):
		word = input().strip()
		library[word].append(ind)
	for ind in range(m):
		word = input().strip()
		if len(library[word]) > 0:
			print(' '.join(map(str, library[word])))
		else:
			print('-1')
__starting_point()


from collections import defaultdict
d = defaultdict(list)
(n, m) = map(int, input().strip().split())
for i in range(1, n + 1):
	d[input().strip()].append(i)
for i in range(m):
	s = ' '.join(map(str, d[input().strip()]))
	if s == '':
		s = -1
	print(s)


from collections import defaultdict
line = input().split(' ')
N = int(line[0])
M = int(line[1])
A = defaultdict(list)
for i in range(N):
	w = input()
	A[w].append(i + 1)
for i in range(M):
	w = input()
	if w not in A:
		print(-1)
	else:
		print(' '.join(map(str, A[w])))


from collections import defaultdict
d = defaultdict(list)
(n, m) = list(map(int, input().split()))
for i in range(n):
	x = input()
	d[x].append(i + 1)
for i in range(m):
	x = input()
	if x in d:
		print(' '.join(map(str, d[x])))
	else:
		print(-1)


from collections import defaultdict
(n, m) = input().split()
cs = defaultdict(lambda : [-1])
for i in range(int(n)):
	c = input()
	if c in cs:
		cs[c].append(i + 1)
		continue
	cs[c] = [i + 1]
for _ in range(int(m)):
	print(' '.join((str(i) for i in cs[input()])))


from collections import defaultdict
(n, m) = map(int, input().split())
d = defaultdict(list)
for i in range(n):
	d['A'].append(input())
for j in range(m):
	d['B'].append(input())
for i in range(m):
	s = []
	for j in range(n):
		if d['B'][i].lower() == d['A'][j].lower():
			s.append(str(j + 1))
	result = ' '.join(s)
	if len(s) > 0:
		print(result)
	else:
		print(-1)


from collections import defaultdict as dd
A = dd(list)
[a, b] = [int(i) for i in input().split()]
for i in range(a):
	word = input()
	A[word].append(str(i + 1))
for i in range(b):
	word = input()
	s = ' '.join(A[word])
	if s == '':
		print(-1)
	else:
		print(s)


from collections import defaultdict
(n, m) = [int(x) for x in input().split()]
d = defaultdict(list)
for x in range(n):
	letter = input()
	d[letter].append(str(x + 1))
for x in range(m):
	letter = input()
	a = d[letter]
	if len(a) > 0:
		print(' '.join(a))
	else:
		print(-1)


from collections import defaultdict
import sys
if sys.version_info[0] >= 3:
	raw_input = input
(N, M) = map(int, raw_input().split())
d = defaultdict(list)
for i in range(N):
	s = raw_input().rstrip()
	d[s].append(i + 1)
for _ in range(M):
	s = raw_input().rstrip()
	if s in d:
		print(' '.join(map(str, d[s])))
	else:
		print('-1')


from collections import defaultdict
(n, m) = map(int, input().split())
d = defaultdict(list)
pos = 1
for i in range(n):
	d[input()].append(str(pos))
	pos += 1
for i in range(m):
	x = input()
	if d[x] == []:
		print(-1)
	else:
		print(' '.join(d[x]))


from collections import defaultdict
(N, M) = map(int, input().split())
d = defaultdict(list)
for i in range(N):
	s = input().rstrip()
	d[s].append(i + 1)
for _ in range(M):
	s = input().rstrip()
	if s in d:
		print(' '.join(map(str, d[s])))
	else:
		print('-1')


import sys
args = [line.strip() for line in sys.stdin]
counts = args[0].split()
items = args[1:]
n = int(counts[0])
m = int(counts[1])
A = items[:n]
B = items[n:]

def indexes(word):
	return [i + 1 for (i, val) in enumerate(A) if val == word]

def stringify(array):
	if len(array) == 0:
		return '-1'
	return ' '.join((str(i) for i in array))
for word in B:
	print(stringify(indexes(word)))


from collections import defaultdict
d = defaultdict(list)
[n, m] = map(int, input().split())
ls = [input() for _ in range(n)]
for i in range(len(ls)):
	el = ls[i]
	if el in d:
		d[el].append(i)
	else:
		d[el].append(i)
find = [input() for _ in range(m)]
for f in find:
	if f in d:
		print(' '.join([str(i + 1) for i in d[f]]))
	else:
		print(-1)


from collections import defaultdict
(n, m) = input().split()
n = int(n)
m = int(m)
d = defaultdict(list)
for i in range(n):
	d['A'].append(input())
l = d['A']
for i in range(m):
	val = input()
	count = 1
	new_l = []
	for j in l:
		if j == val:
			new_l.append(count)
		count += 1
	if len(new_l) == 0:
		print(-1)
	else:
		print(' '.join(map(str, new_l)))


spaces = list(map(int, input().split()))
space_a = {}
for i in range(spaces[0]):
	word = input()
	if word in space_a:
		space_a[word].append(i + 1)
	else:
		space_a[word] = [i + 1]
for i in range(spaces[1]):
	word = input()
	if word in space_a:
		print(' '.join(list(map(str, space_a[word]))))
	else:
		print(-1)


from collections import defaultdict
(n, m) = map(int, input().split())
d = defaultdict(list)
for i in range(n):
	v = input()
	d[v].append(str(i + 1))
for j in range(m):
	v = input()
	if v in d.keys():
		print(' '.join(d[v]))
	else:
		print('-1')


from collections import defaultdict
a = defaultdict(list)
b = defaultdict(list)
length_data = list(map(int, input().split()))
n = length_data[0]
m = length_data[1]
for x in range(1, n + 1):
	key = input()
	a[key].append(x)
for x in range(1, m + 1):
	value = input()
	b[x].append(value)
for x in range(1, m + 1):
	value = b[x]
	value = value[0]
	indexes = list(map(str, a[value]))
	if indexes == []:
		print(-1)
	else:
		print(' '.join(indexes))


(n, m) = map(int, input().split())
a = dict()
for i in range(n):
	word = input()
	if word not in a:
		a[word] = []
	a[word].append(i + 1)
for _ in range(m):
	word = input()
	if word in a:
		print(' '.join(map(str, a[word])))
	else:
		print(-1)


from collections import defaultdict
(n, m) = map(int, input().split())
a = defaultdict(list)
for i in range(n):
	c = input()
	a[c].append(str(i + 1))
for i in range(m):
	c = input()
	if not a[c]:
		print(-1)
	else:
		print(' '.join(a[c]))


from collections import defaultdict
A = defaultdict(list)
nums = input().split()
n = int(nums[0])
m = int(nums[1])
for i in range(1, n + 1):
	word = input()
	A[word].append(i)
for i in range(1, m + 1):
	word = input()
	if A[word]:
		print(' '.join((str(x) for x in A[word])))
	else:
		print(-1)


from collections import defaultdict
d = defaultdict(list)
(n, m) = (int(i) for i in input().split())
position = 0
while position < n:
	st = input()
	d[st].append(position + 1)
	position += 1
position = 0
while position < m:
	st = input()
	print(*d.get(st, [-1]), sep=' ')
	position += 1


from collections import defaultdict
(m, n) = list(map(int, input().split(' ')))
m_dict = defaultdict(list)
n_list = list()
for i in range(m):
	a = input()
	m_dict[a].append(i + 1)
for i in range(n):
	a = input()
	n_list.append(a)
positions = []
for x in n_list:
	enter = False
	for item in m_dict:
		if item == x:
			positions.append(m_dict[x])
			enter = True
	if not enter:
		positions.append([-1])
for position in positions:
	print(' '.join(map(str, position)))


from collections import defaultdict
(size_of_group_a, size_of_group_b) = map(lambda x: int(x), input().split(' '))
group_a = defaultdict(list)
words_to_test = []
for i in range(1, size_of_group_a + 1):
	word = input()
	group_a[word].append(i)
for i in range(0, size_of_group_b):
	words_to_test.append(input())
for word in words_to_test:
	if word not in group_a.keys():
		print('-1')
	else:
		print(' '.join(map(str, group_a[word])))


(n, m) = tuple(map(int, input().split(' ')))
(a, b) = ([], [])
for _ in range(n):
	a.append(input())
for _ in range(m):
	b.append(input())
for y in b:
	r = []
	for x in range(len(a)):
		if a[x] == y:
			r.append(x + 1)
	if len(r) <= 0:
		print(-1)
	else:
		print(' '.join(map(str, r)))


from collections import defaultdict
(n, m) = tuple(map(int, input().split()))
d = defaultdict(list)
for i in range(n):
	d[input()].append(i + 1)
for i in range(m):
	print(' '.join(map(str, d[input()] or [-1])))


from collections import defaultdict
(n, m) = map(int, input().split())
A = defaultdict(list)
for i in range(n):
	A[input()].append(i + 1)
wlist = []
for i in range(m):
	search = input()
	print(*A.get(search, [-1]))


from collections import defaultdict
d = defaultdict(list)
(a, b) = [int(x) for x in input().split()]
li = [input() for x in range(a)]
li2 = [input() for x in range(b)]
li_set = set(li2)
for (index, val) in enumerate(li):
	if val in li_set:
		d[val].append(index + 1)
for i in li2:
	if len(d[i]) != 0:
		print(' '.join(map(str, d[i])))
	else:
		print(-1)


from collections import defaultdict
e = list(map(int, input().split(' ')))
a = e[0]
b = e[1]
d = defaultdict(list)
s = []
c = []
for i in range(a):
	c.append((i + 1, input()))
for y in range(b):
	s.append(input())
for (k, v) in c:
	d[v].append(k)
for y in s:
	if y in d:
		print(' '.join((str(d[y][i]) for i in range(len(d[y])))))
	else:
		print(-1)


lengths = list(map(int, input().split()))
m = []
n = []
for i in range(lengths[0]):
	m.append(input())
for i in range(lengths[1]):
	n.append(input())
for i in range(len(n)):
	indicies = []
	for e in range(len(m)):
		if m[e] == n[i]:
			indicies.append(e + 1)
			m[e] = -1
	if len(indicies) == 0:
		print(-1)
	else:
		print(' '.join(list(map(str, indicies))))
		for z in range(len(m)):
			if m[z] == -1:
				m[z] = n[i]


from collections import defaultdict
(n, m) = input().split()
d = defaultdict(list)
for i in range(int(n)):
	d[input()].append(str(i + 1))
for _ in range(int(m)):
	i = input()
	print(' '.join(d[i])) if d[i] else print(-1)


from collections import defaultdict
d = defaultdict(list)
(a, b) = map(int, input().split())
for x in range(a):
	d[input()].append(x + 1)
for x in range(b):
	key = input()
	if not key in list(d.keys()):
		print(-1)
	else:
		print(' '.join(map(str, d[key])))


from collections import defaultdict
import sys
d = defaultdict(list)
lst = list(map(int, input().split()))
n = lst[0]
m = lst[1]
for i in range(n):
	d[sys.stdin.readline().strip()].append(i + 1)
for i in range(m):
	l = d[sys.stdin.readline().strip()]
	if l:
		print(*l)
	else:
		print(-1)


from collections import defaultdict
in_array = input().split()
if len(in_array) == 2:
	n = int(in_array[0])
	m = int(in_array[1])
	if n >= 1 or n <= 10000 or (m >= 1 and m <= 100):
		d = defaultdict(list)
		index = 1
		while n > 0:
			word = input()
			if len(word) <= 100:
				d[word].append(index)
				n -= 1
				index += 1
		while m > 0:
			k = input()
			if k in d:
				print(' '.join(map(str, sorted(d[k]))))
			else:
				print('-1')
			m -= 1


from collections import defaultdict

def count_str(DDct1, DDct2, Num):
	for j in range(0, int(Num[1])):
		count = []
		for i in range(0, int(Num[0])):
			if DDct2[j] == DDct1[i]:
				count.append(i + 1)
		if len(count) > 0:
			result = ' '.join(map(str, count))
			print(result)
		else:
			print('-1')
Num = input().split(' ')
DDct1 = defaultdict(list)
DDct2 = defaultdict(list)
for i in range(0, int(Num[0])):
	add = input()
	DDct1[i].append(add)
for i in range(0, int(Num[1])):
	add = input()
	DDct2[i].append(add)
count_str(DDct1, DDct2, Num)


from collections import defaultdict
d = defaultdict(list)
(n, m) = list(map(int, input().split()))
for ind in range(n):
	d[input()].append(ind + 1)
for position_for_key in range(m):
	word = input()
	if word in d.keys():
		print(*d[word])
	else:
		print('-1')


from collections import defaultdict
A = defaultdict(list)
(n, m) = list(map(int, input().split()))
for i in range(n):
	a = input()
	if a in A:
		A[a].append(i + 1)
	else:
		A[a] = [i + 1]
for i in range(m):
	a = input()
	if a in A:
		print(' '.join((str(x) for x in A[a])))
	else:
		print(-1)


from collections import defaultdict
d = defaultdict(list)
(n, m) = tuple(map(int, input().split()))
d['A'] = [input() for _ in range(n)]
d['B'] = [input() for _ in range(m)]
for item in d['B']:
	occurences = [str(i + 1) for (i, x) in enumerate(d['A']) if x == item]
	print(' '.join(occurences)) if occurences else print(-1)


from collections import defaultdict
(m, n) = [int(el) for el in input().split()]
a = [input() for _ in range(m)]
b = [input() for _ in range(n)]
index = defaultdict(list)
for (i, el) in enumerate(a):
	index[el].append(i + 1)
for el in b:
	if el in index:
		print(' '.join((str(i) for i in index[el])))
	else:
		print(-1)


(n, m) = map(int, str(input()).split())
N = []
M = []
out = []
for i in range(n):
	N.append(str(input()))
for j in range(m):
	M.append(str(input()))
for k in range(m):
	out.append(sorted({l + 1 for l in range(n) if N[l] == M[k]}))
for p in range(m):
	out[p] = list(map(str, out[p]))
output = []
for o in range(m):
	output.append(' '.join(out[o]))
	if len(output[o]) == 0:
		print(-1)
	else:
		print(output[o])


def check(number, lis):
	return [i for (i, val) in enumerate(lis) if val == number]
(n, m) = input().split()
n = int(n)
m = int(m)
lista = []
for i in range(0, n):
	lista.append(input())
for i in range(0, m):
	p = input()
	m = list(map(lambda x: str(x + 1), check(p, lista)))
	if m == []:
		print(-1)
	else:
		print(' '.join(m))