#include<bits/stdc++.h>
#include<bits/extc++.h>
#define IOS std::ios::sync_with_stdio(false);std::cin.tie(nullptr);std::cout.tie(nullptr);
#define all(x) (x).begin(),(x).end()
#define quchong(x) (x).erase(unique(all(x)),(x).end())
#define Yes(x,y) cout<<((x)?"Yes":"No")<<y
#define yes(x,y) cout<<((x)?"yes":"no")<<y
#define YES(x,y) cout<<((x)?"YES":"NO")<<y
#define ls ((u)<<1)
#define rs ((u)<<1|1)
#define mid (((l)+(r))>>1)
#define lowbit(x) ((x)&(-(x)))
#define itn int
#define asn ans
#define reisze resize
#define pdd pair<double,double>
#define pll pair<LL,LL>
#define pii pair<int,int>
#define tll tuple<LL,LL,LL>
#define tii tuple<int,int,int>
#define plll pair<LLL,LLL>
#define ULL unsigned long long
#define LL long long
#define LLL __int128
#define ld long double
#define ui64 uint64_t
#define ui32 uint32_t
using namespace std;
using namespace __gnu_pbds;
template<typename T>
using RBTree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T>
T fang(const T& a){
return a*a;
}
template<typename T,typename Q>
bool chmax(T& u1,T& u2,const Q& v){
if(v>u1) { u2 = u1, u1 = v;return true;}
if(v>u2){u2=v;return true;}
return false;
}
template<typename T,typename Q>
bool chmin(T& u1,T& u2,const Q& v){
if(v<u1) { u2 = u1, u1 = v;return true;}
if(v<u2){u2=v;return true;}
return false;
}
template<typename T,typename Q>
bool chmin(T& a,const Q& b){
return a > b && (a = b, true);
}
template<typename T,typename Q>
bool chmax(T& a,const Q& b){
return a<b&&(a=b,true);
}
template<typename t1,typename t2>
istream& operator>>(istream& in,pair<t1,t2>& pa){
in>>pa.first>>pa.second;
return in;
}
template<typename t1,typename t2>
ostream& operator<<(ostream& out,const pair<t1,t2>& pa){
out<<pa.first<<' '<<pa.second;
return out;
}
template<typename T>
istream& operator>>(istream& in,vector<T>& arr){
for(auto& v:arr)in>>v;
return in;
}
template<typename T>
ostream& operator<<(ostream& out,const vector<T>& arr){
for(auto& v:arr)out<<v<<' ';
return out;
}
int rand(int l,int r){
static mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
return uniform_int_distribution<int>(l, r)(rng);
}
const ld eps=1e-9;
const int NN=4005;
const int SIZ=1e7;
const LL inf=1e16;
LL mod=998244353;
struct P{
int x,y;
LL w;
};
vector<P> tr[NN*4];
int q;
void build(int u,int l,int r){
tr[u].clear();
if(l==r)return;
}
void _change(int u, int l, int r, int L, int R, P ed){
if(L<=l&&R>=r){
tr[u].emplace_back(ed);
return;
}
if(L<=mid)_change(ls, l, mid, L, R, ed);
if(R>mid)_change(rs, mid + 1, r, L, R, ed);
}
set<int> qu;
vector<LL> ans;
void _insert(int u, int l, int r, int p){
if(l==r){
qu.insert(u);
return;
}
p<=mid ? _insert(ls, l, mid, p) : _insert(rs, mid + 1, r, p);
}
void insert(int p){
_insert(1,1,q,p);
}
void change(int L,int R,P ed){
_change(1,1,q,L,R,ed);
}
int n;
void dfs(int u,int l,int r,vector<vector<LL>> dp){
for(auto [x,y,w]:tr[u]){
if(dp[x][y]<=w)continue;
chmin(dp[x][y],w);
dp[y][x]=dp[x][y];
for(int i=1;i<=n;i++)chmin(dp[i][x],dp[i][y]+dp[y][x]),dp[x][i]=dp[i][x];
for(int i=1;i<=n;i++)chmin(dp[i][y],dp[i][x]+dp[x][y]),dp[y][i]=dp[i][y];
for(int i=1;i<=n;i++)for(int j=1;j<=n;j++){
chmin(dp[i][j],min(dp[i][y]+dp[y][j],dp[i][x]+dp[x][j]));
dp[j][i]=dp[i][j];
}
}
if(l==r){
if(qu.contains(u)){
LL res=0;
for(int i=1;i<=n;i++)for(int j=1;j<=n;j++){
assert(dp[i][j]==dp[j][i]);
if(dp[i][j]<inf)res+=dp[i][j]%mod,res%=mod;
}
ans.emplace_back(res);
}
}else{
dfs(ls,l,mid,dp);
dfs(rs,mid+1,r,dp);
}
}
void solve(){
cin>>n;
int m;
cin>>m;
cin>>q;
qu.clear();
ans.clear();
int id=m;
map<int,pair<int,P>> M;
for(int i=1;i<=m;i++){
int x,y;
LL w;
cin>>x>>y>>w;
M[i]={1,{x,y,w}};
}
build(1,1,q);
for(int i=1;i<=q;i++){
int op;
cin>>op;
if(op==1){
int x,y;
LL w;
cin>>x>>y>>w;
id++;
M[id]={i,{x,y,w}};
}else if(op==2){
int k;
cin>>k;
auto it=M[k];
change(it.first,i,it.second);
M.erase(k);
}else{
insert(i);
}
}
for(auto& [_,it]:M){
change(it.first,q,it.second);
}
vector<vector<LL>> dp(n+1,vector<LL>(n+1));
for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)if(i!=j)dp[i][j]=inf;
dfs(1,1,q,dp);
for(LL v:ans)cout<<v<<'\n';
}
signed main(){
IOS;
int _;
cin>>_;
while(_--)solve();
}