#include "bits/stdc++.h"
using namespace std;

struct shop {
	int id;
	vector<int>prices;
};
struct Edge {
	int from;
	int to;
	int cost;
};
struct aa {
	int now;
	bitset<11>came;
	int cost;
};

class Compare {
public:
	bool operator()(const aa&l, const aa&r) {
		return l.cost > r.cost;
	}
};
int N, Q;
int solve(const vector<vector<Edge>>&edges, const bitset<11>&fst_came) {
	vector<vector<int>>memo(N + 1, vector<int>(1 << (N + 1), 1e9));
	priority_queue<aa, vector<aa>, Compare>que;
	que.push(aa{ 0,fst_came,0 });
	while (!que.empty()) {
		aa atop(que.top());
		que.pop();
		if (atop.now == 0 && atop.came.count() == N + 1)return atop.cost;
		else {
			for (auto e : edges[atop.now]) {
				bitset<11>nextcame(atop.came);
				nextcame[e.to] = true;
				const int nextcost = atop.cost + e.cost;
				if (memo[e.to][nextcame.to_ulong()] > nextcost) {
					memo[e.to][nextcame.to_ulong()] = nextcost;
					que.push(aa{ e.to,nextcame,nextcost });
				}
			}
		}
	}
	return 1e9;
}

int main() {
	while (1) { cin >> N;
		if (!N)break;
		vector<shop>shops;
		{
			map<string, int>mp;
			int num = 0;
			vector<vector<int>>sells(N,vector<int>(2000,1e7));
			for (int i = 0; i < N; ++i) {
				int k; cin >> k;
				shop ash;
				ash.id = i;
				for (int j = 0; j < k; ++j) {
					string st; cin >> st;
					int price; cin >> price;
					if (mp.find(st) == mp.end())mp[st] = num++;
					sells[i][mp[st]] = min(sells[i][mp[st]],price);
				}
			}
			 cin >> Q;
			vector<int>needs(Q);
			for (int i = 0; i < Q; ++i) {
				string st; cin >> st;
				if (mp.find(st) == mp.end())mp[st] = num++;
				needs[i] = mp[st];
			}
			for (int i = 0; i < N; ++i) {
				shop sh;
				sh.id = i;
				for (int j = 0; j < Q; ++j) {
					sh.prices.push_back(sells[i][needs[j]]);
				}
				shops.push_back(sh);
			}
		}
		vector<vector<Edge>>edges(N+1);
		{
			int M; cin >> M;
			for (int i = 0; i < M; ++i) {
				int s, t, d; cin >> s >> t >> d;
				edges[s].push_back(Edge{ s,t,d });
				edges[t].push_back(Edge{ t,s,d });
			}
		}
		pair<int, int>ans(1e7,1e8);
		for (int b = 0; b < (1 << N); ++b) {
			bitset<10>bs(b);
			int price_sum = 0;
			int aprice = 1e8;
			for (int j = 0; j < Q; ++j) {
				int aprice = 1e8;
				for (int i = 0; i < N; ++i) {
					if (bs[i])aprice = min(aprice, shops[i].prices[j]);
				}
				price_sum += aprice;
			}
			if (ans.first < price_sum)continue;
			else {
				bitset<11>came;
				came[0] = true;
				for (int i = 0; i < N; ++i) {
					if (!bs[i])came[i + 1] = true;
				}
				int cost = solve(edges, came);
				if (cost > 5e8)continue;
				else {
					ans = min(ans, make_pair(price_sum, cost));
				}
			}
		}
		if (ans.first > 6e6) {
			cout << "impossible" << endl;
		}
		else {
			cout << ans.first << " " << ans.second << endl;
		}
		
	}
	return 0;
}