#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
vector<set<int>> v(n + 1);
for (int i = 1; i <= n; i++)
{
int k;
cin >> k;
while (k--)
{
int x;
cin >> x;
v[i].insert(x);
}
}
int m;
cin >> m;
while (m--)
{
int a, b;
cin >> a >> b;
int nc = 0, nt;
for (auto c : v[a]) if (v[b].count(c)) nc++;
nt = v[a].size() + v[b].size() - nc;
printf("%.2lf%%\n", nc * 1.0 / nt * 100);
}
return 0;
}