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>
using namespace std;

#define cout cerr
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)

typedef long long ll;
typedef pair<int,int> pii;
#define FR first
#define SE second

inline void rd(int &x){
	x=0;char ch=getchar();int f=1;
	while(ch<'0'||ch>'9'){
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=x*10+ch-'0';
		ch=getchar();
	}
	x*=f;
}

const int Mod=1000000007;
namespace modular{
	int add(int a,int b){return a+b>=Mod?a+b-Mod:a+b;}
	int dec(int a,int b){return a-b<0?a-b+Mod:a-b;}
	int mul(int a,int b){return 1ll*a*b%Mod;}
	int MOD(int x){
		x%=Mod;
		if(x<0)x+=Mod;
		return x;
	}
	int Fast_Pow(int a,int b){
		int res=1;
		while(b){
			if(b&1)res=1ll*res*a%Mod;
			a=1ll*a*a%Mod;
			b>>=1;
		}
		return res;
	}
}using namespace modular;

int n,q;
#define Maxn 305
int a[Maxn],A[Maxn][Maxn];
int inv[Maxn];

int e[Maxn][Maxn];
int num[Maxn][Maxn],h[Maxn];

int pw[Maxn][1305];

const int inf=1e9;
int dt[Maxn];

int sum[Maxn][Maxn];

int lowbit(int x){return x&(-x);}
void ADD(int *hh,int pos,int ad){
	for(int i=pos;i<=n;i+=lowbit(i))hh[i]=add(hh[i],ad);
}
int query(int *hh,int pos){
	int res=0;
	for(int i=pos;i;i-=lowbit(i))res=add(res,hh[i]);
	return res;
}
void Build(){
	rep(i,1,n)rep(j,1,n)sum[i][j]=0;
	per(i,n,1){
		dt[i]=inf;
		if(a[i]>0)dt[i]=0;
		rep(j,i+1,n)
			if(A[i][j])dt[i]=min(dt[i],dt[j]+1);
		if(dt[i]!=inf){
			rep(j,1,i)
				if(num[i][j]){
					sum[j][dt[i]+1]=add(sum[j][dt[i]+1],mul(mul(pw[j][n-dt[i]],num[i][j]),MOD(a[i])));
				}
		}
	}
	rep(i,1,n){
		rep(j,1,n)sum[i][j]=add(sum[i][j-1],sum[i][j]);
		per(j,n,1)sum[i][j]=dec(sum[i][j],sum[i][j^lowbit(j)]);
	}
}

int main(){
	rd(n);
	inv[0]=inv[1]=1;
	rep(i,2,n)inv[i]=mul(Mod-Mod/i,inv[Mod%i]);
	rep(i,1,n){
		pw[i][n]=1;
		per(j,n-1,0)pw[i][j]=mul(pw[i][j+1],inv[i]);
		rep(j,n+1,n+1000)pw[i][j]=mul(i,pw[i][j-1]);
	}
	rep(i,1,n)rd(a[i]);
	rep(i,1,n){
		int sz;
		rd(sz);
		A[i][i]=i;
		rep(j,1,sz){
			int t;rd(t);
			A[i][t]=t;
		}
	}
	rep(i,1,n){
		e[i][i]=1;
		per(j,i-1,1){
			int t=dec(i,j),tmp=0;
			rep(k,j+1,i)tmp=add(tmp,mul(e[i][k],A[j][k]));
			e[i][j]=mul(tmp,inv[t]);
		}
	}
	rep(i,1,n){
		h[i]=1;
		per(j,i,1)
			if(h[j]){
				num[i][j]=h[j];int t=h[j];
				rep(k,1,j)h[k]=dec(h[k],mul(t,e[j][k]));
			}
	}
	rep(i,1,n)
		rep(j,1,n)e[i][j]=add(e[i][j-1],e[i][j]);
	int opt,x,l,r;
	rd(q);
	Build();
	rep(tt,1,q){
		rd(opt);
		if(opt==1){
			rd(x);rd(l);rd(r);
			int res=0;
			rep(i,1,n){
				int tmp=query(sum[i],min(x+1,n));
				res=add(res,mul(mul(tmp,pw[i][x+n]),dec(e[i][r],e[i][l-1])));
			}
			rep(i,l,r)
				if(dt[i]>x)res=add(res,MOD(a[i]));
			printf("%d\n",res);
		}else{
			rd(l);rd(x);
			if(a[l]<=0&&a[l]+x>0){
				a[l]+=x;
				Build();
			}else{
				a[l]+=x;
				if(dt[l]!=inf){
				rep(i,1,l)
					if(num[l][i]){
						ADD(sum[i],dt[l]+1,mul(mul(num[l][i],x),pw[i][n-dt[l]]));
					}		
				}
			}
		}
	}
	return 0;
}