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

#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define all(c) begin(c),end(c)

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;

constexpr int INF=1e9;

int main()
{
	for(int n;cin>>n && n;){
		vector<map<string,int>> ss(n);
		rep(i,n){
			int k; cin>>k;
			rep(j,k){
				string name; int value; cin>>name>>value;
				ss[i][name]=value;
			}
		}
		int q; cin>>q;
		vs ns(q);
		rep(i,q) cin>>ns[i];
		int m; cin>>m;
		vvi d(n+1,vi(n+1,INF));
		rep(i,n+1) d[i][i]=0;
		rep(i,m){
			int u,v,w; cin>>u>>v>>w;
			(u+=n)%=n+1; (v+=n)%=n+1;
			d[u][v]=d[v][u]=w;
		}
		
		rep(k,n+1) rep(i,n+1) rep(j,n+1)
			d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
		
		vvi dp(1<<n+1,vi(n+1,INF));
		rep(i,n) dp[1<<i][i]=d[n][i];
		rep(i,1<<n+1) rep(j,n+1) if(i>>j&1) rep(k,n+1) if(!(i>>k&1))
			dp[i|1<<k][k]=min(dp[i|1<<k][k],dp[i][j]+d[j][k]);
		
		tuple<int,int> res(INF,INF);
		rep(i,1<<n){
			vi ps(q,INF);
			rep(j,n) if(i>>j&1)
				rep(k,q) if(ss[j].count(ns[k]))
					ps[k]=min(ps[k],ss[j][ns[k]]);
			if(count(all(ps),INF)) continue;
			res=min(res,make_tuple(accumulate(all(ps),0),dp[i|1<<n][n]));
		}
		
		if(res==make_tuple(INF,INF))
			cout<<"impossible"<<endl;
		else
			cout<<get<0>(res)<<' '<<get<1>(res)<<endl;
	}
}