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 <cstdio>
#include <vector>
#include <algorithm>
#define pb push_back
using std::vector;
const int N=305, MOD=1000000007;
inline int mval(int x) { return x>=MOD?x-MOD:x; }
inline int fix(int x) { return x+(x>>31&MOD); }
inline void inc(int &x, int a) { x=mval(x+a); }
inline void dec(int &x, int a) { x=fix(x-a); }
inline int qpow(int x, int p)
{ int ret=1; while(p) { if(p&1) ret=1ll*ret*x%MOD; p>>=1, x=1ll*x*x%MOD; } return ret; }

int n, q, a[N], d[N], vec[N][N<<1], tot[N], sum[N][N], sum1[N][N], vsum[N][N], pw[N][1005], ipw[N][1005];
int tr[N][N];
vector<int> c[N];
inline int lowbit(int x) { return x&(-x); }
inline void add(int t, int p, int v) { p=std::max(p, 1); while(p<=n) inc(sum[t][p], v), p+=p&(-p); }
inline int ask(int t, int p) { int ret=0; while(p) inc(ret, sum[t][p]), p-=p&(-p); return ret; }
inline void add1(int t, int p, int v) { p=std::max(p, 1); while(p<=n) inc(sum1[t][p], v), p+=p&(-p); }
inline int ask1(int t, int p) { int ret=0; while(p) inc(ret, sum1[t][p]), p-=p&(-p); return ret; }
void gauss(int n, int m, int a[][N<<1])
{
	for(int i=1; i<=n; ++i)
	{
		int cur=0;
		for(int j=i; j<=n; ++j) if(a[j][i]) { cur=j; break; }
		for(int j=i; j<=m; ++j) std::swap(a[i][j], a[cur][j]);
		int iv=qpow(a[i][i], MOD-2);
		for(int j=i; j<=m; ++j) a[i][j]=1ll*a[i][j]*iv%MOD;
		for(int j=1; j<=n; ++j) if(j!=i)
		{
			int mul=a[j][i];
			for(int k=i; k<=m; ++k) dec(a[j][k], 1ll*mul*a[i][k]%MOD);
		}
	}
}
void build(void)
{
	for(int i=n; i; --i)
	{
		if(a[i]>0) d[i]=0;
		else
		{
			d[i]=n+1;
			for(int j=i+1; j<=n; ++j) if(tr[i][j])
				d[i]=std::min(d[i], d[j]+1);
		}
	}
	for(int i=1; i<=n; ++i) std::fill(sum[i], sum[i]+n+1, 0), std::fill(sum1[i], sum1[i]+n+1, 0);
	std::fill(tot+1, tot+n+1, 0);
	for(int i=1; i<=n; ++i)
	{
		for(int j=1; j<=n; ++j)
		{
			inc(sum[j][std::max(1, d[i])], 1ll*fix(a[i])*vec[i][j]%MOD*ipw[j][d[i]]%MOD);
			inc(sum1[j][std::max(1, d[i])], 1ll*fix(a[i])*vec[i][j]%MOD);
			inc(tot[j], 1ll*fix(a[i])*vec[i][j]%MOD);
		}
	}
	for(int i=1; i<=n; ++i) for(int j=1; j<=n; ++j) if(j+lowbit(j)<=n)
		inc(sum[i][j+lowbit(j)], sum[i][j]), inc(sum1[i][j+lowbit(j)], sum1[i][j]);
}
inline int query(int k, int l, int r)
{
	int ret=0;
	for(int i=1; i<=n; ++i)
	{
		int s1=ask(i, std::min(k, n)), s2=ask1(i, std::min(k, n));
		int t=(1ll*s1*pw[i][k]+MOD+tot[i]-s2)%MOD;
		inc(ret, 1ll*t*(MOD+vsum[i][r]-vsum[i][l-1])%MOD);
	}
	return ret;
}
int main()
{
	scanf("%d", &n);
	for(int i=1; i<=n; ++i) scanf("%d", a+i);
	for(int i=1; i<=n; ++i)
	{
		pw[i][0]=ipw[i][0]=1;
		int iv=qpow(i, MOD-2);
		for(int j=1; j<=1000; ++j)
		{
			pw[i][j]=1ll*pw[i][j-1]*i%MOD;
			ipw[i][j]=1ll*ipw[i][j-1]*iv%MOD;
		}
	}
	for(int i=1, k; i<=n; ++i)
	{
		scanf("%d", &k);
		tr[i][i]=i;
		for(int j=1, x; j<=k; ++j) scanf("%d", &x), tr[i][x]=x;
	}
	for(int i=1; i<=n; ++i)
	{
		int d=i;
		vec[i][i]=1;
		for(int j=i-1; j; --j)
		{
			int res=0;
			for(int t=j+1; t<=n; ++t) if(tr[j][t]) inc(res, 1ll*t*vec[i][t]%MOD);
			vec[i][j]=1ll*res*qpow(i-j, MOD-2)%MOD;
		}
		for(int j=1; j<=n; ++j) vsum[i][j]=mval(vsum[i][j-1]+vec[i][j]);
	}
	for(int i=1; i<=n; ++i) vec[i][i+n]=1;
	gauss(n, n*2, vec);
	for(int i=1; i<=n; ++i) std::copy(vec[i]+n+1, vec[i]+2*n+1, vec[i]+1);
	scanf("%d", &q);
	build();
	for(int i=1, op, x, y, z; i<=q; ++i)
	{
		scanf("%d%d%d", &op, &x, &y);
//		build();
		if(op==1) scanf("%d", &z), printf("%d\n", query(x, y, z));
		else
		{
			a[x]+=y;
			if(a[x]>0&&a[x]-y<=0) build();
			else
			{
				for(int i=1; i<=n; ++i)
				{
					add(i, d[x], 1ll*y*vec[x][i]%MOD*ipw[i][d[x]]%MOD);
					add1(i, d[x], 1ll*y*vec[x][i]%MOD);
					inc(tot[i], 1ll*y*vec[x][i]%MOD);
				}
			}
		}
	}
	return 0;
}