#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int maxn=2e5;
int q,n=1,v[maxn+1];
vector<int> g[maxn+1];
ll pv[maxn+1];
void dfs(int u)
{
	for(int v:g[u])dfs(v);
	int tt=1;
	pv[u]=v[u];
	for(int v:g[u]){pv[u]+=pv[v];tt++;}
	pv[u]%=mod;
	pv[u]*=tt;
	pv[u]%=mod;
}
int main()
{
	scanf("%d %d",&v[n],&q);
	bool change = true;
	rep(i,1,q)
	{
		int t;
		scanf("%d ",&t);
		if(t == 1) {
			int p;
			++n;
			scanf("%d %d\n",&p,&v[n]);
			g[p].push_back(n);
			change = true;
		}else {
			int x;
			scanf("%d\n",&x);
			if(change) {
				dfs(1);
			}
			printf("%lld\n",pv[x]);
			change = false;
		}
	}
	return 0;
}
