        // #pragma GCC optimize("Ofast")
        // #pragma GCC optimize ("unroll-loops")
        // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
     
        #include <bits/stdc++.h>
        #include <ext/pb_ds/assoc_container.hpp> 
        #include <ext/pb_ds/tree_policy.hpp> 
        using namespace std;
        using namespace __gnu_pbds;
     
        typedef long long int ll;
        #define endl '\n'
        #define ld long double
        #define all(a) a.begin(),a.end()
        #define int long long
        #define pb push_back
        #define pii pair <int, int>
        #define ff first
        #define ss second
        #define sz(v) (int)v.size() 
        #define UB upper_bound
        #define LB lower_bound
        #define BP(x) __builtin_popcountll(x)
        #define PQS priority_queue <pii, vector<pii>, greater<pii> > 
        #define OST tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>
        mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
        int getRand(int l, int r) {
          uniform_int_distribution<int> uid(l, r);
          return uid(rng);
        }
     
        const int INF = 1e9 + 0;
        const int mod = 1e9 + 7;
        //const int mod = 998244353;
        const int N = 2e5 + 5;
     
        int dp[11][11][11][11][11];
        int dist[5][N];
        int p;
        int node[15];
     
        int go(int ind, int a, int b, int c, int d) {
          if(ind > p) return 0;
          int &x = dp[ind][a][b][c][d];
          if(x != -1) return x;
          x = INF;
          if(a > 0) {
            x = min(x, dist[1][node[ind]] + go(ind+1,a-1,b,c,d));
          }
          if(b > 0) {
            x = min(x, dist[2][node[ind]] + go(ind+1,a,b-1,c,d));
          }
          if(c > 0) {
            x = min(x, dist[3][node[ind]] + go(ind+1,a,b,c-1,d));
          }
          if(d > 0) {
            x = min(x, dist[4][node[ind]] + go(ind+1,a,b,c,d-1));
          }
          return x;
        }
     
        void solve() {
          memset(dp,-1,sizeof(dp));
          int n, m;
          cin >> n >> m;
          vector <pii> adj[n+5];
          while(m--) {
            int x, y, w;
            cin >> x >> y >> w;
            adj[x].pb({y,w});
            adj[y].pb({x,w});
          }
          for(int i = 1; i <= 4; i++) {
            for(int j = 1; j <= n; j++) {
              dist[i][j] = INF;
            }
          }
          int k; cin >> k;
          int of[k+2], em[k+2];
          for(int i = 1; i <= k; i++) {
            cin >> of[i] >> em[i];
          }
          cin >> p;
          for(int i = 1; i <= p; i++) {
            cin >> node[i];
          }
          for(int i = 1; i <= k; i++) {
            dist[i][of[i]] = 0;
            PQS Q;
            Q.push({0,of[i]});
            while(!Q.empty()) {
              auto cur = Q.top();
              Q.pop();
              int x = cur.ss, d = cur.ff;
              if(dist[i][x] < d) continue;
              for(auto j : adj[x]) {
                if(dist[i][j.ff] > d + j.ss) {
                  dist[i][j.ff] = d + j.ss;  
                  Q.push({dist[i][j.ff],j.ff});
                }
              }
            }
          }
          // cout << "here";
          for(int i = 1; i <= 4; i++) {
            em[i] = max(0ll, em[i]-1);
            em[i] = min(em[i],10ll);
          }
          int ans = go(1,em[1],em[2],em[3],em[4]);
          if(ans >= INF) ans = -1;
          cout << ans << '\n';
        }
     
        signed main() {   
          ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
     
          #ifndef ONLINE_JUDGE
           freopen("input.txt", "r", stdin);
          //  freopen("output.txt", "w", stdout);
          #endif
           int t = 1; cin >> t;
           for(int i = 1; i <= t; i++) {
             solve();
          }
        }    
     
        /*
         
        */