li = [0] * 60
n = int(input())
for i in range(1,n + 1):
# m,*v = list(map(int,input().split())) 这么写也可以
v = map(int,input().split()[1:])
li[i] = set(v)
k = int(input())
while k > 0:
k -= 1
a,b = map(int,input().split())
nc = len(li[a] & li[b])
nt = len(li[a] | li[b])
print(f'{nc / nt * 100:.1f}%')