/*Python to C++
T = 1
def init():
global T
#T = _I()
from collections import Counter
def solve():
N,M = _M()
dp = lis(2,N,N,inf)
for i in _R(N):
dp[i][i] = 0
for i in _R(M):
a,b,h = _M()
dp[a-1][b-1] = min(dp[a-1][b-1],h)
dp[b-1][a-1] = min(dp[b-1][a-1],h)
K,T = _M()
D = _L()
for i in _R(K):
for j in _R(i+1,K):
dp[D[i]-1][D[j]-1] = min(dp[D[i]-1][D[j]-1],T)
dp[D[j]-1][D[i]-1] = min(dp[D[j]-1][D[i]-1],T)
for k in _R(N):
for i in _R(N):
for j in _R(N):
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])
Q = _I()
for i in _R(Q):
q = _L()
if q[0] == 1:
x,y,t = q[1::]
queue = []
if dp[x-1][y-1] > t:
dp[x-1][y-1] = t
dp[y-1][x-1] = t
queue.append((x-1,y-1,t))
p = 0
while p < len(queue):
x,y,t = queue[p]
for i in _R(N):
if dp[x][i] > t+dp[y][i]:
dp[x][i] = t+dp[y][i]
dp[i][x] = t+dp[y][i]
queue.append((x,i,dp[x][i]))
if dp[y][i] > t+dp[x][i]:
dp[y][i] = t+dp[x][i]
dp[i][y] = t+dp[x][i]
queue.append((y,i,dp[y][i]))
p += 1
if q[0] == 2:
x = q[1]
queue = []
for i in D:
if dp[i-1][x-1] > T:
dp[i-1][x-1] = T
dp[x-1][i-1] = T
queue.append((i-1,x-1,T))
D.append(x)
p = 0
while p < len(queue):
x,y,t = queue[p]
for i in _R(N):
if dp[x][i] > t+dp[y][i]:
dp[x][i] = t+dp[y][i]
dp[i][x] = t+dp[y][i]
queue.append((x,i,dp[x][i]))
if dp[y][i] > t+dp[x][i]:
dp[y][i] = t+dp[x][i]
dp[i][y] = t+dp[x][i]
queue.append((y,i,dp[y][i]))
p += 1
if q[0] == 3:
cnt = 0
for i in _R(N):
for j in _R(N):
if dp[i][j] != inf:
cnt += dp[i][j]
print(cnt)
#--------------ごっつりしていってね--------------
#あぁそうそう ごちうさ楽しみ
import sys
import math
from copy import deepcopy as dc
sys.setrecursionlimit(10 ** 6)
from collections import defaultdict as dd
import heapq
from itertools import permutations as per
_S = input;_R = range;_P = print; _E = enumerate;
def _RR(a): return range(a-1,-1,-1)
def _I(): return int(_S())
def _M(): return map(int, _S().split())
def _SS(): return _S().strip().split()
def _L(): return list(_M())
def _LS(): return list(_S())
def _T(): return tuple(_M())
def yn(b):
print("Yes" if b else "No")
return b
def fs(b): print("First" if b else "Second")
def lis(c,*a):
if not len(a): return 0 if c == 0 else []
if c == 0: return a[0]
return [lis(c-1,*a[1:]) for i in _R(a[0])]
def in2(a,fn):
for i in _R(len(a)): a[i]=fn()
biga = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";smaa = "abcdefghijklmnopqrstuvwxyz"
ctoi = lambda c: ord(c) - ord('a')
ctoi2 = lambda c: ord(c) - ord('A')
itoc = lambda i: chr(ord('a') + i)
itoc2 = lambda i: chr(ord('A') + i)
inf = 10 ** 18
mod = 998244353
def around(x,y,type_=False):
rt = []
rt.extend([(x+1,y),(x-1,y),(x,y+1),(x,y-1)])
if type_:
rt.extend([(x+1,y+1),(x-1,y-1),(x-1,y+1),(x+1,y-1)])
return rt
def acc(a):
b = [0]
for i in a:
b.append(b[-1] + i)
return b
class heap:
l = []
def __init__(self,*s): self.l = list(s);heapq.heapify(self.l)
def min(self): return False if (len(self.l) == 0) else self.l[0]
def pop(self): return False if (len(self.l) == 0) else heapq.heappop(self.l)
def push(self,n): heapq.heappush(self.l,n)
def dump(self): return heapq.nsmallest(len(self.l),self.l)
def max(self): return False if (len(self.l) == 0) else heapq.nlargest(1,self.l)[0]
def len(self): return len(self.l)
class base:
bn = 0; dig = 0; num = []
def __init__(self,base_num,digit = 0):
self.bn = base_num; self.dig = digit; self.num = [0]*digit
def max(self): return(self.bn**self.dig-1)
def dump(self): return(self.num[::-1])
def ncp(self,digit,n): self.num[digit] = min(self.num[digit]+n,self.bn-1)
def plus(self,digit,n):
for i in _R(digit-self.dig+1): self.num.append(0)
self.dig = max(self.dig,digit+1)
if (self.num[digit]+n >= self.bn):
self.plus(digit+1,(self.num[digit]+n)//self.bn)
self.num[digit] = (self.num[digit]+n)%self.bn
def copy(self,n):
self.num = dc(n)
dig = len(self.num)
def change(self,n):
digit = int(math.log(n,self.bn))if n!=0 else 0+1
for i in _R(digit-self.dig+1): self.num.append(0)
self.dig = max(self.dig,digit+1)
for i in _R(self.dig):
self.num[i] = n%self.bn**(i+1)//self.bn**i
n -= self.num[i]
return self.dump()
def b10(self): return(sum([self.num[i]*self.bn**i for i in _R(self.dig)]))
def gin(N, M=None):
g = [[] for _ in range(N)]
for _ in range(N-1 if M is None else M):
u, v = map(int, input().split());u -= 1;v -= 1
g[u].append(v);g[v].append(u)
return g
def ginh(N, M):
g = [[] for _ in range(N)]
for i in range(M):
u, v, h = map(int, input().split());u -= 1;v -= 1
g[u].append((v,h));#g[v].append((u,h))
return g
from atcoder.segtree import SegTree
class rhash:
hs = None
def __init__(self,S,N):
self.hs = SegTree(msum,0,[ctoi(S[i])*pow(31,i,mod) for i in _R(N)])
def get(self,l,r):
return self.hs.prod(l,r+1)*pow(pow(31,l,mod),mod-2,mod)%mod
def getall(self):
return self.hs.all_prod()
def change(self,n,c):
self.hs.set(n,ctoi(c)*pow(31,n,mod))
def nwse(s,x,y,rev=False):
if (rev):
s = {"N":"S","S":"N","W":"E","E":"W"}[s]
if s=="N": return (x-1,y)
elif s=="W": return (x,y-1)
elif s=="S": return (x+1,y)
elif s=="E": return (x,y+1)
init()
for i in _R(T):
solve()
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, M;
cin >> N >> M;
vector<vector<ll>> dp(N, vector<ll>(N, INF));
for (int i = 0; i < N; ++i) dp[i][i] = 0;
for (int i = 0; i < M; ++i) {
int a, b;
ll h;
cin >> a >> b >> h;
--a, --b;
dp[a][b] = min(dp[a][b], h);
dp[b][a] = min(dp[b][a], h);
}
int K, T;
cin >> K >> T;
vector<int> D(K);
for (int i = 0; i < K; ++i) {
cin >> D[i];
D[i]--;
}
// 空港の初期接続
for (int i = 0; i < K; ++i) {
for (int j = i + 1; j < K; ++j) {
dp[D[i]][D[j]] = min(dp[D[i]][D[j]], 1LL * T);
dp[D[j]][D[i]] = min(dp[D[j]][D[i]], 1LL * T);
}
}
// ワーシャル–フロイド
for (int k = 0; k < N; ++k)
for (int i = 0; i < N; ++i)
for (int j = 0; j < N; ++j)
if (dp[i][k] < INF && dp[k][j] < INF)
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
int Q;
cin >> Q;
while (Q--) {
int type;
cin >> type;
if (type == 1) {
int x, y;
ll t;
cin >> x >> y >> t;
--x, --y;
queue<tuple<int, int, ll>> que;
if (dp[x][y] > t) {
dp[x][y] = t;
dp[y][x] = t;
que.emplace(x, y, t);
}
while (!que.empty()) {
auto [a, b, cost] = que.front();
que.pop();
for (int i = 0; i < N; ++i) {
if (dp[a][i] > cost + dp[b][i]) {
dp[a][i] = cost + dp[b][i];
dp[i][a] = cost + dp[b][i];
que.emplace(a, i, dp[a][i]);
}
if (dp[b][i] > cost + dp[a][i]) {
dp[b][i] = cost + dp[a][i];
dp[i][b] = cost + dp[a][i];
que.emplace(b, i, dp[b][i]);
}
}
}
} else if (type == 2) {
int x;
cin >> x;
--x;
queue<tuple<int, int, ll>> que;
for (int i : D) {
if (dp[i][x] > T) {
dp[i][x] = T;
dp[x][i] = T;
que.emplace(i, x, T);
}
}
D.push_back(x);
while (!que.empty()) {
auto [a, b, cost] = que.front();
que.pop();
for (int i = 0; i < N; ++i) {
if (dp[a][i] > cost + dp[b][i]) {
dp[a][i] = cost + dp[b][i];
dp[i][a] = cost + dp[b][i];
que.emplace(a, i, dp[a][i]);
}
if (dp[b][i] > cost + dp[a][i]) {
dp[b][i] = cost + dp[a][i];
dp[i][b] = cost + dp[a][i];
que.emplace(b, i, dp[b][i]);
}
}
}
} else if (type == 3) {
ll total = 0;
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
if (dp[i][j] < INF) {
total += dp[i][j];
}
}
}
cout << total << '\n';
}
}
return 0;
}