#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> Tree;
#define sz(x) (int)(x).size()
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair <int, int>
#define vi vector<int>
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define f0r(i,a) for(int i=0;i<a;i++)
#define f1r(i,a,b) for(int i=a;i<b;i++)
#define read1(a) int a; scanf("%d", &a)
#define read2(a,b) int a,b; scanf("%d %d", &a, &b)
#define read3(a,b,c) int a,b,c; scanf("%d %d %d", &a, &b, &c)
#define read(n,arr) int arr[n]; f0r(i,n){ scanf("%d", &arr[i]); }
#define print1(a) printf("%d \n", a)
#define print2(a, b) printf("%d %d \n", a, b)
#define print3(a, b, c) printf("%d %d %d \n", a, b, c)
#define print(v) for (int i : v) { printf("%d ", i); } printf("\n")
#define debug printf("asdf\n");
#define newl printf("\n");
#define usaco(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout);
void fast_io(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
}
void io(string taskname){
string fin = taskname + ".in";
string fout = taskname + ".out";
const char* FIN = fin.c_str();
const char* FOUT = fout.c_str();
freopen(FIN, "r", stdin);
freopen(FOUT, "w", stdout);
fast_io();
}
const long long INF = 1e18;
template<class T, int SZ> struct LazySegTree {
T sum[2*SZ], mn[2*SZ], lazy[2*SZ]; // set SZ to a power of 2
LazySegTree() {
memset (sum,0,sizeof sum);
memset (mn,0,sizeof mn);
memset (lazy,0,sizeof lazy);
}
void push(int ind, int L, int R) {
sum[ind] += (R-L+1)*lazy[ind];
mn[ind] += lazy[ind];
if (L != R) lazy[2*ind] += lazy[ind], lazy[2*ind+1] += lazy[ind];
lazy[ind] = 0;
}
void pull(int ind) {
sum[ind] = sum[2*ind]+sum[2*ind+1];
mn[ind] = max(mn[2*ind],mn[2*ind+1]);
}
void build() {
for(int i = SZ-1;i>=0; i--){
pull(i);
}
}
T qsum(int lo, int hi, int ind = 1, int L = 0, int R = SZ-1) {
push(ind,L,R);
if (lo > R || L > hi) return 0;
if (lo <= L && R <= hi) return sum[ind];
int M = (L+R)/2;
return qsum(lo,hi,2*ind,L,M) + qsum(lo,hi,2*ind+1,M+1,R);
}
T qmax(int lo, int hi, int ind = 1, int L = 0, int R = SZ-1) {
push(ind,L,R);
if (lo > R || L > hi) return 0;
if (lo <= L && R <= hi) return mn[ind];
int M = (L+R)/2;
return max(qmax(lo,hi,2*ind,L,M), qmax(lo,hi,2*ind+1,M+1,R));
}
void upd(int lo, int hi, long long inc, int ind = 1, int L = 0, int R = SZ-1) {
push(ind,L,R);
if (hi < L || R < lo) return;
if (lo <= L && R <= hi) {
lazy[ind] = inc;
push(ind,L,R);
return;
}
int M = (L+R)/2;
upd(lo,hi,inc,2*ind,L,M); upd(lo,hi,inc,2*ind+1,M+1,R);
pull(ind);
}
};
vector<vector<ll>> graph;
template <class T, int V>
struct HeavyLight {
int parent[V], heavy[V], depth[V];
int root[V], treePos[V];
LazySegTree<T, V> tree;
template <class G>
int dfs(const G& graph, int v) {
int size = 1, maxSubtree = 0;
for (int u : graph[v]) if (u != parent[v]) {
parent[u] = v;
depth[u] = depth[v] + 1;
int subtree = dfs(graph, u);
if (subtree > maxSubtree) heavy[v] = u, maxSubtree = subtree;
size += subtree;
}
return size;
}
template <class BinaryOperation>
void processPath(int u, int v, BinaryOperation op) {
for (; root[u] != root[v]; v = parent[root[v]]) {
if (depth[root[u]] > depth[root[v]]) swap(u, v);
op(treePos[root[v]], treePos[v]);
}
if (depth[u] > depth[v]) swap(u, v);
op(treePos[u], treePos[v]);
}
template <class G>
void init(const G& graph) {
int n = graph.size();
fill_n(heavy, n, -1);
parent[0] = -1;
depth[0] = 0;
dfs(graph, 0);
for (int i = 0, currentPos = 0; i < n; ++i)
if (parent[i] == -1 || heavy[parent[i]] != i)
for (int j = i; j != -1; j = heavy[j]) {
root[j] = i;
treePos[j] = currentPos++;
}
tree.build();
}
void set(int u, int value){
int cur = tree.qsum(treePos[u], treePos[u]);
tree.upd(u, u, value-cur);
}
void modifyPath(int u, int v, const T& value) {
processPath(u, v, [this, &value](int l, int r) { tree.upd(l, r, value); });
}
long long queryPath(int u, int v) {
long long res = 0;
processPath(u, v, [this, &res](int l, int r) { res += (tree.qmax(l, r)); });
return res;
}
};
HeavyLight<ll, 1<<17> H;
int main(){
fast_io();
ll n;
cin >> n;
graph.resize(n+1);
f0r(i, n-1){
int a, b;
cin >> a >> b;
a--; b--;
graph[a].eb(b);
graph[b].eb(a);
}
H.init(graph);
int q;
cin >> q;
f0r(i, q){
char c;
ll u, v;
cin >> c >> u >> v;
u--;
// cout << c << " " << u << " " << v << endl;
if(c == 'I'){
H.modifyPath(u, u, v);
}
else{
v--;
cout <<H.queryPath(u, v) << endl;
}
}
return 0;
}
I3ByYWdtYSBjb21tZW50KGxpbmtlciwgIi9zdGFjazoyMDAwMDAwMDAiKQovLyNwcmFnbWEgR0NDIG9wdGltaXplKCJPZmFzdCIpCi8vI3ByYWdtYSBHQ0MgdGFyZ2V0KCJzc2Usc3NlMixzc2UzLHNzc2UzLHNzZTQscG9wY250LGFibSxtbXgsYXZ4LHR1bmU9bmF0aXZlIikKI3ByYWdtYSBHQ0Mgb3B0aW1pemUgKCJPMyIpCiNwcmFnbWEgR0NDIHRhcmdldCAoInNzZTQiKQojaW5jbHVkZSA8Yml0cy9zdGRjKysuaD4KI2luY2x1ZGUgPGV4dC9wYl9kcy90cmVlX3BvbGljeS5ocHA+CiNpbmNsdWRlIDxleHQvcGJfZHMvYXNzb2NfY29udGFpbm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iwwLHNpemVvZiBtbik7CiAgICAgICAgbWVtc2V0IChsYXp5LDAsc2l6ZW9mIGxhenkpOwogICAgfQoKICAgIHZvaWQgcHVzaChpbnQgaW5kLCBpbnQgTCwgaW50IFIpIHsKICAgICAgICBzdW1baW5kXSArPSAoUi1MKzEpKmxhenlbaW5kXTsKICAgICAgICBtbltpbmRdICs9IGxhenlbaW5kXTsKICAgICAgICBpZiAoTCAhPSBSKSBsYXp5WzIqaW5kXSArPSBsYXp5W2luZF0sIGxhenlbMippbmQrMV0gKz0gbGF6eVtpbmRdOwogICAgICAgIGxhenlbaW5kXSA9IDA7CiAgICB9CgogICAgdm9pZCBwdWxsKGludCBpbmQpIHsKICAgICAgICBzdW1baW5kXSA9IHN1bVsyKmluZF0rc3VtWzIqaW5kKzFdOwogICAgICAgIG1uW2luZF0gPSBtYXgobW5bMippbmRdLG1uWzIqaW5kKzFdKTsKICAgIH0KCiAgICB2b2lkIGJ1aWxkKCkgewogICAgICAgIGZvcihpbnQgaSA9IFNaLTE7aT49MDsgaS0tKXsKICAgICAgICAgICAgcHVsbChpKTsKICAgICAgICB9CiAgICB9CgogICAgVCBxc3VtKGludCBsbywgaW50IGhpLCBpbnQgaW5kID0gMSwgaW50IEwgPSAwLCBpbnQgUiA9IFNaLTEpIHsKICAgICAgICBwdXNoKGluZCxMLFIpOwogICAgICAgIGlmIChsbyA+IFIgfHwgTCA+IGhpKSByZXR1cm4gMDsKICAgICAgICBpZiAobG8gPD0gTCAmJiBSIDw9IGhpKSByZXR1cm4gc3VtW2luZF07CgogICAgICAgIGludCBNID0gKEwrUikvMjsKICAgICAgICByZXR1cm4gcXN1bShsbyxoaSwyKmluZCxMLE0pICsgcXN1bShsbyxoaSwyKmluZCsxLE0rMSxSKTsKICAgIH0KCiAgICBUIHFtYXgoaW50IGxvLCBpbnQgaGksIGludCBpbmQgPSAxLCBpbnQgTCA9IDAsIGludCBSID0gU1otMSkgewogICAgICAgIHB1c2goaW5kLEwsUik7CiAgICAgICAgaWYgKGxvID4gUiB8fCBMID4gaGkpIHJldHVybiAwOwogICAgICAgIGlmIChsbyA8PSBMICYmIFIgPD0gaGkpIHJldHVybiBtbltpbmRdOwoKICAgICAgICBpbnQgTSA9IChMK1IpLzI7CiAgICAgICAgcmV0dXJuIG1heChxbWF4KGxvLGhpLDIqaW5kLEwsTSksIHFtYXgobG8saGksMippbmQrMSxNKzEsUikpOwogICAgfQoKICAgIHZvaWQgdXBkKGludCBsbywgaW50IGhpLCBsb25nIGxvbmcgaW5jLCBpbnQgaW5kID0gMSwgaW50IEwgPSAwLCBpbnQgUiA9IFNaLTEpIHsKICAgICAgICBwdXNoKGluZCxMLFIpOwogICAgICAgIGlmIChoaSA8IEwgfHwgUiA8IGxvKSByZXR1cm47CiAgICAgICAgaWYgKGxvIDw9IEwgJiYgUiA8PSBoaSkgewogICAgICAgICAgICBsYXp5W2luZF0gPSBpbmM7CiAgICAgICAgICAgIHB1c2goaW5kLEwsUik7CiAgICAgICAgICAgIHJldHVybjsKICAgICAgICB9CgogICAgICAgIGludCBNID0gKEwrUikvMjsKICAgICAgICB1cGQobG8saGksaW5jLDIqaW5kLEwsTSk7IHVwZChsbyxoaSxpbmMsMippbmQrMSxNKzEsUik7CiAgICAgICAgcHVsbChpbmQpOwogICAgfQp9Owp2ZWN0b3I8dmVjdG9yPGxsPj4gZ3JhcGg7CnRlbXBsYXRlIDxjbGFzcyBULCBpbnQgVj4Kc3RydWN0IEhlYXZ5TGlnaHQgewogIGludCBwYXJlbnRbVl0sIGhlYXZ5W1ZdLCBkZXB0aFtWXTsKICBpbnQgcm9vdFtWXSwgdHJlZVBvc1tWXTsKICBMYXp5U2VnVHJlZTxULCBWPiB0cmVlOwoKICB0ZW1wbGF0ZSA8Y2xhc3MgRz4KICBpbnQgZGZzKGNvbnN0IEcmIGdyYXBoLCBpbnQgdikgewogICAgaW50IHNpemUgPSAxLCBtYXhTdWJ0cmVlID0gMDsKICAgIGZvciAoaW50IHUgOiBncmFwaFt2X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m9yIChpbnQgaiA9IGk7IGogIT0gLTE7IGogPSBoZWF2eVtqXSkgewogICAgICAgICAgcm9vdFtqXSA9IGk7CiAgICAgICAgICB0cmVlUG9zW2pdID0gY3VycmVudFBvcysrOwogICAgICAgIH0KICAgIHRyZWUuYnVpbGQoKTsKICB9CgogICAgdm9pZCBzZXQoaW50IHUsIGludCB2YWx1ZSl7CiAgICAgICAgaW50IGN1ciA9IHRyZWUucXN1bSh0cmVlUG9zW3VdLCB0cmVlUG9zW3VdKTsKICAgICAgICB0cmVlLnVwZCh1LCB1LCB2YWx1ZS1jdXIpOwogICAgfQogIHZvaWQgbW9kaWZ5UGF0aChpbnQgdSwgaW50IHYsIGNvbnN0IFQmIHZhbHVlKSB7CiAgICBwcm9jZXNzUGF0aCh1LCB2LCBbdGhpcywgJnZhbHVlXShpbnQgbCwgaW50IHIpIHsgdHJlZS51cGQobCwgciwgdmFsdWUpOyB9KTsKICB9CgogIGxvbmcgbG9uZyBxdWVyeVBhdGgoaW50IHUsIGludCB2KSB7CiAgICBsb25nIGxvbmcgcmVzID0gMDsKICAgIHByb2Nlc3NQYXRoKHUsIHYsIFt0aGlzLCAmcmVzXShpbnQgbCwgaW50IHIpIHsgcmVzICs9ICh0cmVlLnFtYXgobCwgcikpOyB9KTsKICAgIHJldHVybiByZXM7CiAgfQp9OwoKSGVhdnlMaWdodDxsbCwgMTw8MTc+IEg7CgppbnQgbWFpbigpewogICAgZmFzdF9pbygpOwogICAgbGwgbjsKICAgIGNpbiA+PiBuOwogICAgZ3JhcGgucmVzaXplKG4rMSk7CiAgICBmMHIoaSwgbi0xKXsKICAgICAgICBpbnQgYSwgYjsKICAgICAgICBjaW4gPj4gYSA+PiBiOwogICAgICAgIGEtLTsgYi0tOwogICAgICAgIGdyYXBoW2FdLmViKGIpOwogICAgICAgIGdyYXBoW2JdLmViKGEpOwogICAgfQogICAgSC5pbml0KGdyYXBoKTsKICAgIGludCBxOwogICAgY2luID4+IHE7CiAgICBmMHIoaSwgcSl7CiAgICAgICAgY2hhciBjOwogICAgICAgIGxsIHUsIHY7CiAgICAgICAgY2luID4+IGMgPj4gdSA+PiB2OwogICAgICAgIHUtLTsKICAgICAgLy8gIGNvdXQgPDwgYyA8PCAiICIgPDwgdSA8PCAiICIgPDwgdiA8PCBlbmRsOwogICAgICAgIGlmKGMgPT0gJ0knKXsKICAgICAgICAgICAgSC5tb2RpZnlQYXRoKHUsIHUsIHYpOwogICAgICAgIH0KICAgICAgICBlbHNlewogICAgICAgICAgICB2LS07CiAgICAgICAgICAgIGNvdXQgPDxILnF1ZXJ5UGF0aCh1LCB2KSA8PCBlbmRsOwogICAgICAgIH0KICAgIH0KICAgIHJldHVybiAwOwp9Cg==