/**
* author: Vi Gia Huy
* Vi Gia Huy will win APIO
**/
#include <bits/stdc++.h>
using namespace std;
const int N = 5e4 + 3;
const int Q = 1e5 + 6;
int n, m, q;
struct Node {
int to;
long long d;
int id;
};
vector<Node> adj[N];
struct Query {
int type;
int b;
long long r;
int s;
long long w;
} qu[Q];
namespace sub1 {
bool check[N];
int dfs(int u, long long w) {
int res = 1;
for (Node it : adj[u]) {
int v = it.to;
long long d = it.d;
if (check[v]) continue;
if (w <= d) {
check[v] = true;
res += dfs(v, w);
}
}
return res;
}
void sol() {
for (int qi = 1; qi <= q; qi++) {
if (qu[qi].type == 1) {
for (int i = 1; i <= n; i++) {
for (Node& it : adj[i]) {
if (it.id == qu[qi].b) {
it.d = qu[qi].r;
}
}
}
}
else {
for (int i = 1; i <= n; i++) check[i] = false;
check[qu[qi].s] = true;
int res = dfs(qu[qi].s, qu[qi].w);
cout << res << "\n";
}
}
return;
}
}
namespace sub2 {
void sol() {
return;
}
}
namespace sub3 {
void sol() {
return;
}
}
namespace sub4 {
void sol() {
return;
}
}
namespace sub5 {
void sol() {
return;
}
}
namespace sub6 {
void sol() {
return;
}
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
bool checksub2 = true;
bool checksub3 = false;
bool checksub4 = true;
int tmp = 1;
for (int k = 1; k <= 15; k++) {
tmp *= 2;
if (n == tmp - 1) checksub3 = true;
}
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int u, v; cin >> u >> v;
long long d; cin >> d;
adj[u].push_back({v, d, i});
adj[v].push_back({u, d, i});
if (u != i || v != i + 1) checksub2 = false;
if (u != (i + 1) / 2 || v != i + 1) checksub3 = false;
}
cin >> q;
for (int i = 1; i <= q; i++) {
cin >> qu[i].type;
if (qu[i].type == 1) cin >> qu[i].b >> qu[i].r;
else cin >> qu[i].s >> qu[i].w;
if (qu[i].type == 1) checksub4 = false;
}
if (n <= 1e3 && m <= 1e3 && q <= 1e4) sub1::sol();
else if (m == n - 1 && checksub2) sub2::sol();
else if (m == n - 1 && checksub3) sub3::sol();
else if (checksub4) sub4::sol();
else if (m == n - 1) sub5::sol();
else sub6::sol();
return 0;
}