#include #include #include using namespace std;constexpr long long MOD=998244353;struct Function{int type=3,pos=0;long long value=1;vectorcalls;}; int main(){ios::sync_with_stdio(false);cin.tie(nullptr);int n;cin>>n;vectora(n);for(auto&x:a)cin>>x;int m;cin>>m;vectorf(m+1);vectorindegree(m+1);for(int i=0;i>f[i].type;if(f[i].type==1){cin>>f[i].pos>>f[i].value;--f[i].pos;}else if(f[i].type==2)cin>>f[i].value;else{int c;cin>>c;f[i].calls.resize(c);for(int&x:f[i].calls){cin>>x;--x;++indegree[x];}}}int q;cin>>q;f[m].calls.resize(q);for(int&x:f[m].calls){cin>>x;--x;++indegree[x];}queueque;for(int i=0;i<=m;++i)if(indegree[i]==0)que.push(i);vectortopo;while(!que.empty()){int u=que.front();que.pop();topo.push_back(u);for(int v:f[u].calls)if(--indegree[v]==0)que.push(v);}vectormul(m+1,1);for(auto it=topo.rbegin();it!=topo.rend();++it){int u=*it;if(f[u].type==2)mul[u]=f[u].value%MOD;else if(f[u].type==3)for(int v:f[u].calls)mul[u]=mul[u]*mul[v]%MOD;}vectorcoef(m+1);coef[m]=1;for(int u:topo)if(f[u].type==3){long long suffix=1;for(auto it=f[u].calls.rbegin();it!=f[u].calls.rend();++it){int v=*it;coef[v]=(coef[v]+coef[u]*suffix)%MOD;suffix=suffix*mul[v]%MOD;}}for(auto&x:a)x=x*mul[m]%MOD;for(int i=0;i