#include using namespace std; const long long mod = 1e9 + 7; enum { LEFT, RIGHT }; struct node { node *parent = nullptr; node *lch = nullptr; node *rch = nullptr; bool rev = false; long long lazy = 0; long long coef = 0; long long value = 0; long long sum_coef = 0; long long sum = 0; node(long long value, long long coef) : value(value), coef(coef) { sum_coef = coef; sum = value; } int direction() { if (parent == nullptr) return -1; return parent->lch == this ? LEFT : RIGHT; } bool is_root() { return parent == nullptr || (parent->lch != this && parent->rch != this); } }; void connect(node *child, node *parent, int dir) { if (parent != nullptr) (dir == LEFT ? parent->lch : parent->rch) = child; if (child != nullptr) child->parent = parent; } long long sum_coef(node *x) { return x == nullptr ? 0 : x->sum_coef; } long long sum(node *x) { return x == nullptr ? 0 : (x->sum + x->lazy * sum_coef(x)) % mod; } void update(node *x) { if (x == nullptr) return; x->sum_coef = (x->coef + sum_coef(x->lch) + sum_coef(x->rch)) % mod; x->sum = (x->value + sum(x->lch) + sum(x->rch)) % mod; } void push(node *x) { if (x == nullptr) return; for (node *y : { x->lch, x->rch }) if (y != nullptr) { (y->lazy += x->lazy) %= mod; y->rev ^= x->rev; } if (x->rev) swap(x->lch, x->rch); (x->value += x->lazy * x->coef) %= mod; x->lazy = 0; x->rev = false; update(x); } void raise(node *x) { node *y = x->parent; node *z = y->parent; int ydir = y->direction(); bool is_root = y->is_root(); if (x->direction() == LEFT) { connect(x->rch, y, LEFT); connect(y, x, RIGHT); } else { connect(x->lch, y, RIGHT); connect(y, x, LEFT); } if (is_root) { x->parent = z; } else { connect(x, z, ydir); } update(y); update(x); update(z); } void splay(node *x) { while (!x->is_root()) { if (x->parent->parent != nullptr) push(x->parent->parent); push(x->parent); push(x); if (x->parent->is_root()) { raise(x); } else { if (x->direction() == x->parent->direction()) { raise(x->parent); raise(x); } else { raise(x); raise(x); } } } push(x); } void expose(node *x) { node *rch = nullptr; node *y = x; while (y != nullptr) { splay(y); assert(y->lazy == 0); y->rch = rch; rch = y; update(y); y = y->parent; } splay(x); } void cut(node *x) { expose(x); x->lch->parent = nullptr; x->lch = nullptr; update(x); } void link(node *x, node *p) { expose(x); expose(p); x->parent = p; p->rch = x; update(x); update(p); } void evert(node *x) { expose(x); x->rch = x->lch; x->lch = nullptr; if (x->rch != nullptr) x->rch->rev ^= 1; update(x); } void add(node *x, long long value) { (x->value += value * x->coef) %= mod; if (x->lch != nullptr) (x->lch->lazy += value) %= mod; update(x); } vector g[101010]; node *tr[101010]; void dfs(int curr, int prev) { for (int next : g[curr]) if (next != prev) { link(tr[next], tr[curr]); dfs(next, curr); } } int main() { int n; cin >> n; vector S(n), C(n); for (int i = 0; i < n; i++) scanf("%d", &S[i]); for (int i = 0; i < n; i++) scanf("%d", &C[i]); for (int i = 0; i < n; i++) tr[i] = new node(S[i], C[i]); for (int i = 0; i < n - 1; i++) { int u, v; scanf("%d %d", &u, &v); u--; v--; g[u].push_back(v); g[v].push_back(u); } dfs(0, -1); int q; cin >> q; for (int i = 0; i < q; i++) { int k; scanf("%d", &k); if (k == 0) { int x, y, z; scanf("%d %d %d", &x, &y, &z); x--; y--; evert(tr[x]); expose(tr[y]); add(tr[y], z); } else { int x, y; scanf("%d %d", &x, &y); x--; y--; evert(tr[x]); expose(tr[y]); long long ans = (tr[y]->value + sum(tr[y]->lch)) % mod; printf("%lld\n", ans); } } }