Problem: Note that the memory limit is unusual.

There are n chefs numbered 1, 2, …, n that must prepare dishes for a king. Chef i has skill i and initially has a dish of tastiness a_i where |a_i| ≤ i. Each chef has a list of other chefs that he is allowed to copy from. To stop chefs from learning bad habits, the king makes sure that chef i can only copy from chefs of larger skill.

There are a sequence of days that pass during which the chefs can work on their dish. During each day, there are two stages during which a chef can change the tastiness of their dish. 

  1. At the beginning of each day, each chef can choose to work (or not work) on their own dish, thereby multiplying the tastiness of their dish of their skill (a_i := i ⋅ a_i) (or doing nothing).
  2. After all chefs (who wanted) worked on their own dishes, each start observing the other chefs. In particular, for each chef j on chef i's list, chef i can choose to copy (or not copy) j's dish, thereby adding the tastiness of the j's dish to i's dish (a_i := a_i + a_j) (or doing nothing). It can be assumed that all copying occurs simultaneously. Namely, if chef i chooses to copy from chef j he will copy the tastiness of chef j's dish at the end of stage 1.



All chefs work to maximize the tastiness of their own dish in order to please the king.

Finally, you are given q queries. Each query is one of two types.

  1. 1 k l r — find the sum of tastiness a_l, a_{l+1}, …, a_{r} after the k-th day. Because this value can be large, find it modulo 10^9 + 7. 
  2. 2 i x — the king adds x tastiness to the i-th chef's dish before the 1-st day begins (a_i := a_i + x). Note that, because the king wants to see tastier dishes, he only adds positive tastiness (x > 0). 



Note that queries of type 1 are independent of each all other queries. Specifically, each query of type 1 is a scenario and does not change the initial tastiness a_i of any dish for future queries. Note that queries of type 2 are cumulative and only change the initial tastiness a_i of a dish. See notes for an example of queries.

Input

The first line contains a single integer n (1 ≤ n ≤ 300) — the number of chefs.

The second line contains n integers a_1, a_2, …, a_n (-i ≤ a_i ≤ i).

The next n lines each begin with a integer c_i (0 ≤ c_i < n), denoting the number of chefs the i-th chef can copy from. This number is followed by c_i distinct integers d (i < d ≤ n), signifying that chef i is allowed to copy from chef d during stage 2 of each day.

The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^5) — the number of queries.

Each of the next q lines contains a query of one of two types: 

  * 1 k l r (1 ≤ l ≤ r ≤ n; 1 ≤ k ≤ 1000); 
  * 2 i x (1 ≤ i ≤ n; 1 ≤ x ≤ 1000). 



It is guaranteed that there is at least one query of the first type.

Output

For each query of the first type, print a single integer — the answer to the query.

Example

Input


5
1 0 -2 -2 4
4 2 3 4 5
1 3
1 4
1 5
0
7
1 1 1 5
2 4 3
1 1 1 5
2 3 2
1 2 2 4
2 5 1
1 981 4 5


Output


57
71
316
278497818

Note

Below is the set of chefs that each chef is allowed to copy from:

  * 1: \{2, 3, 4, 5\} 
  * 2: \{3\} 
  * 3: \{4\} 
  * 4: \{5\} 
  * 5: ∅ (no other chefs)



Following is a description of the sample.

For the first query of type 1, the initial tastiness values are [1, 0, -2, -2, 4].

The final result of the first day is shown below: 

  1. [1, 0, -2, -2, 20] (chef 5 works on his dish). 
  2. [21, 0, -2, 18, 20] (chef 1 and chef 4 copy from chef 5). 



So, the answer for the 1-st query is 21 + 0 - 2 + 18 + 20 = 57.

For the 5-th query (3-rd of type 1). The initial tastiness values are now [1, 0, 0, 1, 4].

Day 1

  1. [1, 0, 0, 4, 20] (chefs 4 and 5 work on their dishes). 
  2. [25,0, 4, 24, 20] (chef 1 copies from chefs 4 and 5, chef 3 copies from chef 4, chef 4 copies from chef 5). 



Day 2

  1. [25, 0, 12, 96, 100] (all chefs but chef 2 work on their dish). 
  2. [233, 12, 108, 196, 100] (chef 1 copies from chefs 3, 4 and 5, chef 2 from 3, chef 3 from 4, chef 4 from chef 5).

So, the answer for the 5-th query is 12+108+196=316. 




It can be shown that, in each step we described, all chefs moved optimally.

Solution (in CPP):

Solution:
#include<bits/stdc++.h>
namespace my_std{
	using namespace std;
	#define pii pair<int,int>
	#define fir first
	#define sec second
	#define MP make_pair
	#define rep(i,x,y) for (int i=(x);i<=(y);i++)
	#define drep(i,x,y) for (int i=(x);i>=(y);i--)
	#define go(x) for (int i=head[x];i;i=edge[i].nxt)
	#define templ template<typename T>
	#define sz 333
	#define mod 1000000007ll
	typedef long long ll;
	typedef double db;
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	templ inline T rnd(T l,T r) {return uniform_int_distribution<T>(l,r)(rng);}
	templ inline bool chkmax(T &x,T y){return x<y?x=y,1:0;}
	templ inline bool chkmin(T &x,T y){return x>y?x=y,1:0;}
	templ inline void read(T& t)
	{
		t=0;char f=0,ch=getchar();double d=0.1;
		while(ch>'9'||ch<'0') f|=(ch=='-'),ch=getchar();
		while(ch<='9'&&ch>='0') t=t*10+ch-48,ch=getchar();
		if(ch=='.'){ch=getchar();while(ch<='9'&&ch>='0') t+=d*(ch^48),d*=0.1,ch=getchar();}
		t=(f?-t:t);
	}
	template<typename T,typename... Args>inline void read(T& t,Args&... args){read(t); read(args...);}
	char __sr[1<<21],__z[20];int __C=-1,__zz=0;
	inline void Ot(){fwrite(__sr,1,__C+1,stdout),__C=-1;}
	inline void print(int x)
	{
		if(__C>1<<20)Ot();if(x<0)__sr[++__C]='-',x=-x;
		while(__z[++__zz]=x%10+48,x/=10);
		while(__sr[++__C]=__z[__zz],--__zz);__sr[++__C]='\n';
	}
	void file()
	{
		#ifdef NTFOrz
		freopen("a.in","r",stdin);
		#endif
	}
	inline void chktime()
	{
		#ifdef NTFOrz
		cerr<<clock()/1000.0<<'\n';
		#endif
	}
	#ifdef mod
	ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x%mod) if (y&1) ret=ret*x%mod;return ret;}
	ll inv(ll x){return ksm(x,mod-2);}
	#else
	ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x) if (y&1) ret=ret*x;return ret;}
	#endif
//	inline ll mul(ll a,ll b){ll d=(ll)(a*(double)b/mod+0.5);ll ret=a*b-d*mod;if (ret<0) ret+=mod;return ret;}
}
using namespace my_std;

int n;
ll a[sz]; int d[sz];
vector<int>E[sz];

ll A[sz][sz],V[sz][sz],C[sz][sz];
// A: ×ªÒÆ¾ØÕó
// V[i]: µÚ i ¸öÌØÕ÷ÏòÁ¿
// C[i]: \sum C[i][j]*V[j] = e[i] 

void init()
{
	rep(i,1,n) A[i][i]=i;
	rep(i,1,n) for (auto v:E[i]) A[i][v]=v;
	rep(i,1,n)
	{
		V[i][i]=1;
		drep(j,i,1) { if (j!=i) V[i][j]=mod-V[i][j]*inv(i-j)%mod; drep(k,j-1,1) (V[i][k]+=mod-V[i][j]*A[k][j]%mod)%=mod; }
	}
	rep(i,1,n)
	{
		C[i][i]=1;
		drep(j,i,1) drep(k,j-1,1) (C[i][k]+=mod-C[i][j]*V[j][k]%mod)%=mod;
	}
	rep(i,1,n) rep(j,1,n) (V[i][j]+=V[i][j-1])%=mod;
}
int id[sz],pos[sz],D[sz]; ll val[sz][sz];
ll tr[sz][sz];
void add(ll *tr,int x,ll w){assert(w>=0);while (x<=n) (tr[x]+=w)%=mod,x+=x&-x;}
ll query(ll *tr,int x){ll res=0;while (x) res+=tr[x],x-=x&-x;assert(res>=0);return res%mod;}
void rebuild()
{
	drep(i,n,1) if (a[i]>0) d[i]=0; else { d[i]=1e9; for (auto v:E[i]) chkmin(d[i],d[v]+1); }
	rep(i,1,n) id[i]=i; sort(id+1,id+n+1,[](int x,int y){return d[x]<d[y];}); rep(i,1,n) D[i]=d[id[i]],pos[id[i]]=i;
	rep(j,1,n) rep(i,1,n) val[j][i]=C[i][j]*ksm(j,mod-1-d[i])%mod,tr[j][i]=0;
	rep(j,1,n) rep(i,1,n) add(tr[j],pos[i],(a[i]+mod)*val[j][i]%mod);
}

int main()
{
	file();
	read(n);
	rep(i,1,n) read(a[i]);
	rep(i,1,n) { int c,x; read(c); while (c--) read(x),E[i].push_back(x); }
	init(); rebuild();
	int Q; read(Q);
	while (Q--)
	{
		int tp,x,y,z; read(tp,x,y);
		if (tp==1)
		{
			read(z);
			int p=lower_bound(D+1,D+n+1,x)-D-1; ll ans=0;
			rep(j,1,n) (ans+=(V[j][z]-V[j][y-1]+mod)*ksm(j,x)%mod*query(tr[j],p)%mod)%=mod;
			rep(i,y,z) if (d[i]>=x) (ans+=a[i]+mod)%=mod;
			printf("%lld\n",ans);
		}
		else { ll t=a[x]; a[x]+=y; if (t<=0&&a[x]>0) rebuild(); else rep(j,1,n) add(tr[j],pos[x],val[j][x]*y%mod); }
	}
	return 0;
}