#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<vector<int>> v;
for (int i = 0; i < n; i++) {
int m; cin >> m;
vector<int> a(m);
for (int j = 0; j < m; j++) {
cin >> a[j];
}
sort(a.begin(), a.end());
a.erase(unique(a.begin(), a.end()), a.end());
v.push_back(a);
}
int q;
cin >> q;
while (q--) {
int a1, a2;
cin >> a1 >> a2;
a1 -= 1, a2 -= 1;
vector<int> _union, _insect;
set_union(v[a1].begin(), v[a1].end(), v[a2].begin(), v[a2].end(), inserter(_union, _union.begin()));
set_intersection(v[a1].begin(), v[a1].end(), v[a2].begin(), v[a2].end(), inserter(_insect, _insect.begin()));
double sz1 = _insect.size(), sz2 = _union.size();
cout << fixed << setprecision(2) << sz1 / sz2 * 100 << "%" << "\n"[q == 0];
}
return 0;
}
//4.16
//4.8
//