include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=100010;
const int p=1000000007;
ll C[maxn<<2];
int cnt[maxn<<2][6],sz[maxn],w[maxn],id[maxn],vs[maxn],pos;
int head[maxn],num;
int prime[]={2,3,5,7,11,13};
struct E
{
int to,next;
}edge[maxn];
inline void add_edge(int u,int v)
{
edge[num].to=v;
edge[num].next=head[u];
head[u]=num++;
return;
}
inline void dfs(int u,int p)
{
id[u]=++pos;
vs[pos]=u;
sz[u]=1;
for(int i=head[u];i!=-1;i=edge[i].next)
{
int v=edge[i].to;
if(v!=p){
dfs(v,u);
sz[u]+=sz[v];
}
}
return;
}
inline void pushup(int rt)
{
for(int i=0;i<6;i++)
cnt[rt][i]=cnt[rt<<1][i]+cnt[rt<<1|1][i];
C[rt]=C[rt<<1]C[rt<<1|1]%p;
}
inline void build(int l,int r,int rt)
{
if(l==r){
C[rt]=w[vs[l]];
int val=w[vs[l]];
for(int i=0;val&&i<6;i++)
{
int k=0;
while(val%prime[i]==0){++k;val/=prime[i];}
cnt[rt][i]+=k;
}
return;
}
int mid=l+r>>1;
build(l,mid,rt<<1);
build(mid+1,r,rt<<1|1);
pushup(rt);
return;
}
inline void update(int pos,int val,int l,int r,int rt)
{
if(l==r){
C[rt]=C[rt]val%p;
for(int i=0;val&&i<6;i++)
{
int k=0;
while(val%prime[i]==0){++k;val/=prime[i];}
cnt[rt][i]+=k;
}
return;
}
int mid=l+r>>1;
if(pos<=mid) update(pos,val,l,mid,rt<<1);
else update(pos,val,mid+1,r,rt<<1|1);
pushup(rt);
}
inline void Query(int L,int R,int l,int r,int rt,ll&ans,intnum)
{
if(L<=l&&R>=r){
ans=ansC[rt]%p;
for(int i=0;i<6;i++) num[i]+=cnt[rt][i];
return;
}
int mid=l+r>>1;
if(L<=mid) Query(L,R,l,mid,rt<<1,ans,num);
if(R>mid) Query(L,R,mid+1,r,rt<<1|1,ans,num);
return;
}
int main()
{
//freopen("a.txt","r",stdin);
memset(head,-1,sizeof(head));
int n;
scanf("%d",&n);
for(int i=1;i<n;i++)
{
int u,v;
scanf("%d%d",&u,&v);
++u,++v;
add_edge(u,v);
}
for(int i=1;i<=n;i++) scanf("%d",&w[i]);
dfs(1,0);
build(1,n,1);
int q;
char op[100];
scanf("%d",&q);
while(q--)
{
scanf("%s",op);
if(op[0]=='S'){
int u,x;
scanf("%d%d",&u,&x);
++u;
update(id[u],x,1,n,1);
}
else{
int u;
scanf("%d",&u);
++u;
ll ans=1,ans2=1;
int num[6]={0};
Query(id[u],id[u]+sz[u]-1,1,n,1,ans,num);
for(int i=0;i<6;i++)
{
ans2=(num[i]+1)%p*ans2%p;
}
printf("%lld %lld\n",ans,ans2);
}
}
return 0;
}