#include <bits/stdc++.h>
using namespace std;
#define ll long long
// #define int ll
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n+1)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define pii pair<int, int>
#define f first
#define s second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)((x).size())
#define pb push_back
#define endl '\n'
#define IOS() ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
const ll maxn = 2e5+5;
int n, mod, q;
vector<int> g[maxn];
vector<int> H(maxn);
ll pw(ll a, ll p){
ll ret = 1;
while(p > 0){
if (p & 1){
ret *= a;
ret %= mod;
}
a *= a;
a %= mod;
p >>= 1;
}
return ret;
}
ll inv(ll a){
return pw(a, mod-2);
}
void dfs(int u, int cd, int val, int pre){
if (cd < 0) return;
H[u] = ((ll)(H[u]) * val)%mod;
for (auto v:g[u]){
if (v != pre) dfs(v, cd-1, val, u);
}
}
void modify(int U, int D, int W){
dfs(U, D, W, -1);
}
int query(int U){
return H[U];
}
signed main(){
IOS();
cin>>n>>mod;
REP(i, n-1){
int u, v; cin>>u>>v;
g[u].pb(v); g[v].pb(u);
}
REP1(i, n) cin>>H[i];
cin>>q;
REP(i, q){
int t; cin>>t;
if (t == 1){
int a, b, c; cin>>a>>b>>c;
modify(a, b, c);
}
else{
int x; cin>>x;
cout<<query(x)<<endl;
}
}
}
/*
4 7
1 2
2 3
3 4
1
1
1
1
11
1 2 1 2
1 1 0 2
2 1
2 2
2 3
2 4
1 4 10 2
2 1
2 2
2 3
2 4
5 12
1 2
1 3
3 4
1 5
6
1
3
5
3
6
1 2 2 3
1 3 2 3
1 5 2 7
2 3
2 1
2 4
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |