#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;
}
I2luY2x1ZGU8Y3N0ZGlvPgojaW5jbHVkZTxjc3RyaW5nPgojaW5jbHVkZTxhbGdvcml0aG0+CiNpbmNsdWRlPHZlY3Rvcj4KI2RlZmluZSByZXAoaSxhLGIpIGZvcihpbnQgaT1hO2k8PWI7aSsrKQp1c2luZyBuYW1lc3BhY2Ugc3RkOwp0eXBlZGVmIGxvbmcgbG9uZyBsbDsKY29uc3QgbGwgbW9kID0gMTAwMDAwMDAwNzsKY29uc3QgaW50IG1heG49MmU1OwppbnQgcSxuPTEsdlttYXhuKzFdOwp2ZWN0b3I8aW50PiBnW21heG4rMV07CmxsIHB2W21heG4rMV07CnZvaWQgZGZzKGludCB1KQp7Cglmb3IoaW50IHY6Z1t1XSlkZnModik7CglpbnQgdHQ9MTsKCXB2W3VdPXZbdV07Cglmb3IoaW50IHY6Z1t1XSl7cHZbdV0rPXB2W3ZdO3R0Kys7fQoJcHZbdV0lPW1vZDsKCXB2W3VdKj10dDsKCXB2W3VdJT1tb2Q7Cn0KaW50IG1haW4oKQp7CglzY2FuZigiJWQgJWQiLCZ2W25dLCZxKTsKCWJvb2wgY2hhbmdlID0gdHJ1Z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