#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define pb push_back
#define ff first
#define ss second
#define pi pair<int,int>
struct tr{
int u, v, w;
};
const int N = 1001;
vector<tr> b;
vector<pi> a[N];
int n,m;
int c;
void dfs(int x, int w, int p){
c ++;
for(auto i : a[x]){
if(i.ff != p && i.ss >= w) dfs(i.ff, w, x);
}
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m;
for(int i=0; i < m ; i ++){
int q,w,e ; cin >> q >> w >> e;
b.pb({q,w,e});
a[q].pb({w,e});
a[w].pb({q,e});
}
int t; cin >> t;
while(t--){
int p,l,r; cin >> p >> l >> r;
if(p == 1){
for(auto &j : a[b[l-1].u])
if(j.ff == b[l-1].v && j.ss == b[l-1].w){ j.ss = r; break;}
for(auto &j : a[b[l-1].v])
if(j.ff == b[l-1].u && j.ss == b[l-1].w){ j.ss = r; break;}
b[l-1].w = r;
// for(int i=1; i <= n; i ++){
// cout << i << ": ";
// for(auto j : a[i]) cout << j.ff << "," << j.ss << " ";
// cout << '\n';
// }
// cout << '\n';
}
else{
c = 0;
dfs(l, r, -1);
cout << c << '\n';
}
}
}