//tonynater
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int maxn = 200010;
int v[maxn], q, n = 1, qstore[maxn][2]; //input
int parent[maxn]; //tree
vector<int> children[maxn]; //tree
int curtravpos, traversal[maxn], bounds[maxn][2]; //traversal
int activechildren[maxn]; //processing
void dfs(int u) {
traversal[curtravpos] = u;
bounds[u][0] = curtravpos;
++curtravpos;
for(auto v : children[u]) {
dfs(v);
}
bounds[u][1] = curtravpos-1;
}
struct segment_tree {
int b, e;
segment_tree *lst, *rst;
int sum;
ll mult;
segment_tree(int _b, int _e) {
b = _b;
e = _e;
sum = 0;
mult = 1;
lst = rst = NULL;
if(b < e) {
lst = new segment_tree(b,(b+e)/2);
rst = new segment_tree((b+e)/2+1,e);
merge();
}
}
void prop() {
if(mult > 1) {
sum = sum*mult%mod;
if(lst != NULL) {
lst->mult = lst->mult*mult%mod;
rst->mult = rst->mult*mult%mod;
}
mult = 1;
}
}
void merge() {
if(lst != NULL) {
sum = (lst->sum+rst->sum)%mod;
}
}
void rmult(int l, int r, int m) {
if(m == 1) {
return;
}
prop();
if(e < l || r < b) {
return;
}else if(l <= b && e <= r) {
mult = m;
prop();
}else {
lst->rmult(l,r,m);
rst->rmult(l,r,m);
merge();
}
}
void set(int idx, int v) {
prop();
if(b == idx && idx == e) {
sum = v;
}else if(idx <= (b+e)/2) {
lst->set(idx,v);
rst->prop();
merge();
}else {
lst->prop();
rst->set(idx,v);
merge();
}
}
int get(int l, int r) {
prop();
if(e < l || r < b) {
return 0;
}else if(l <= b && e <= r) {
return sum;
}else {
int lsum = lst->get(l,r);
int rsum = rst->get(l,r);
return (lsum+rsum)%mod;
}
}
};
ll binpow(ll base, int exp) {
if(exp == 0) {
return 1;
}else {
ll half = binpow(base,exp/2);
ll full = half*half%mod;
if(exp%2) {
full = full*base%mod;
}
return full;
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cin >> v[0] >> q;
for(int i = 0; i < q; i++) {
cin >> qstore[i][0] >> qstore[i][1];
--qstore[i][1];
if(qstore[i][0] == 1) {
parent[n] = qstore[i][1];
cin >> v[n];
children[parent[n]].push_back(n);
qstore[i][1] = n;
++n;
}
}
dfs(0);
segment_tree *st_root = new segment_tree(0,n-1);
st_root->set(0,v[0]);
for(int i = 0; i < q; i++) {
int x = qstore[i][1];
if(qstore[i][0] == 1) {
int par = parent[x];
int lb = bounds[par][0], rb = bounds[par][1];
int curchildren = ++activechildren[par];
int mult = binpow(curchildren,mod-2)*(curchildren+1)%mod;
st_root->rmult(lb,rb,mult);
int parmultfactor = st_root->get(lb,lb)*binpow(v[par],mod-2)%mod;
int childval = ll(parmultfactor)*v[x]%mod;
st_root->set(bounds[x][0],childval);
}else {
int rootres = st_root->get(bounds[x][0],bounds[x][1]);
int scale = 1;
if(x > 0) {
scale = st_root->get(bounds[parent[x]][0],bounds[parent[x]][0])
*binpow(v[parent[x]],mod-2)%mod;
}
int res = rootres*binpow(scale,mod-2)%mod;
cout << res << '\n';
}
}
return 0;
}
Ly90b255bmF0ZXIKCiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPHZlY3Rvcj4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp0eXBlZGVmIGxvbmcgbG9uZyBsbDsKCmNvbnN0IGxsIG1vZCA9IDEwMDAwMDAwMDc7Cgpjb25zdCBpbnQgbWF4biA9IDIwMDAxMDsKCmludCB2W21heG5dLCBxLCBuID0gMSwgcXN0b3JlW21heG5dWzJdOyAvL2lucHV0CgppbnQgcGFyZW50W21heG5dOyAvL3RyZWUKdmVjdG9yPGludD4gY2hpbGRyZW5bbWF4bl07IC8vdHJlZQoKaW50IGN1cnRyYXZwb3MsIHRyYXZlcnNhbFttYXhuXSwgYm91bmRzW21heG5dWzJdOyAvL3RyYXZlcnNhbAoKaW50IGFjdGl2ZWNoaWxkcmVuW21heG5dOyAvL3Byb2Nlc3NpbmcKCnZvaWQgZGZzKGludCB1KSB7CiAgICB0cmF2ZXJzYWxbY3VydHJhdnBvc10gPSB1OwogICAgYm91bmRzW3VdWzBdID0gY3VydHJhdnBvczsKICAgICsrY3VydHJhdnBvczsKICAgIGZvcihhdXRvIHYgOiBjaGlsZHJlblt1XSkgewogICAgICAgIGRmcyh2KTsKICAgIH0KICAgIGJvdW5kc1t1XVsxXSA9IGN1cnRyYXZwb3MtMTsKfQoKc3RydWN0IHNlZ21lbnRfdHJlZSB7CiAgICBpbnQgYiwgZTsKICAgIHNlZ21lbnRfdHJlZSAqbHN0LCAqcnN0OwogICAgCiAgICBpbnQgc3VtOwogICAgbGwgbXVsdDsKICAgIAogICAgc2VnbWVudF90cmVlKGludCBfYiwgaW50IF9lKSB7CiAgICAgICAgYiA9IF9iOwogICAgICAgIGUgPSBfZTsKICAgICAgICBzdW0gPSAwOwogICAgICAgIG11bHQgPSAxOwogICAgICAgIGxzdCA9IHJzdCA9IE5VTEw7CiAgICAgICAgaWYoYiA8IGUpIHsKICAgICAgICAgICAgbHN0ID0gbmV3IHNlZ21lbnRfdHJlZShiLChiK2UpLzIpOwogICAgICAgICAgICByc3QgPSBuZXcgc2VnbWVudF90cmVlKChiK2UpLzIrMSxlKTsKICAgICAgICAgICAgbWVyZ2UoKTsKICAgICAgICB9CiAgICB9CiAgICAKICAgIHZvaWQgcHJvcCgpIHsKICAgICAgICBpZihtdWx0ID4gMSkgewogICAgICAgICAgICBzdW0gPSBzdW0qbXVsdCVtb2Q7CiAgICAgICAgICAgIGlmKGxzdCAhPSBOVUxMKSB7CiAgICAgICAgICAgICAgICBsc3QtPm11bHQgPSBsc3QtPm11bHQqbXVsdCVtb2Q7CiAgICAgICAgICAgICAgICByc3QtPm11bHQgPSByc3QtPm11bHQqbXVsdCVtb2Q7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgbXVsdCA9IDE7CiAgICAgICAgfQogICAgfQogICAgCiAgICB2b2lkIG1lcmdlKCkgewogICAgICAgIGlmKGxzdCAhPSBOVUxMKSB7CiAgICAgICAgICAgIHN1bSA9IChsc3QtPnN1bStyc3QtPnN1bSklbW9kOwogICAgICAgIH0KICAgIH0KICAgIAogICAgdm9pZCBybXVsdChpbnQgbCwgaW50IHIsIGludCBtKSB7CiAgICAgICAgaWYobSA9PSAxKSB7CiAgICAgICAgICAgIHJldHVybjsKICAgICAgICB9CiAgICAgICAgcHJvcCgpOwogICAgICAgIGlmKGUgPCBsIHx8IHIgPCBiKSB7CiAgICAgICAgICAgIHJldHVybjsKICAgICAgICB9ZWxzZSBpZihsIDw9IGIgJiYgZSA8PSByKSB7CiAgICAgICAgICAgIG11bHQgPSBtOwogICAgICAgICAgICBwcm9wKCk7CiAgICAgICAgfWVsc2UgewogICAgICAgICAgICBsc3QtPnJtdWx0KGwscixtKTsKICAgICAgICAgICAgcnN0LT5ybXVsdChsLHIsbSk7CiAgICAgICAgICAgIG1lcmdlKCk7CiAgICAgICAgfQogICAgfQogICAgCiAgICB2b2lkIHNldChpbnQgaWR4LCBpbnQgdikgewogICAgICAgIHByb3AoKTsKICAgICAgICBpZihiID09IGlkeCAmJiBpZHggPT0gZSkgewogICAgICAgICAgICBzdW0gPSB2OwogICAgICAgIH1lbHNlIGlmKGlkeCA8PSAoYitlKS8yKSB7CiAgICAgICAgICAgIGxzdC0+c2V0KGlkeCx2KTsKICAgICAgICAgICAgcnN0LT5wcm9wKCk7CiAgICAgICAgICAgIG1lcmdlKCk7CiAgICAgICAgfWVsc2UgewogICAgICAgICAgICBsc3QtPnByb3AoKTsKICAgICAgICAgICAgcnN0LT5zZXQoaWR4LHYpOwogICAgICAgICAgICBtZXJnZSgpOwogICAgICAgIH0KICAgIH0KICAgIAogICAgaW50IGdldChpbnQgbCwgaW50IHIpIHsKICAgICAgICBwcm9wKCk7CiAgICAgICAgaWYoZSA8IGwgfHwgciA8IGIpIHsKICAgICAgICAgICAgcmV0dXJuIDA7CiAgICAgICAgfWVsc2UgaWYobCA8PSBiICYmIGUgPD0gcikgewogICAgICAgICAgICByZXR1cm4gc3VtOwogICAgICAgIH1lbHNlIHsKICAgICAgICAgICAgaW50IGxzdW0gPSBsc3QtPmdldChsLHIpOwogICAgICAgICAgICBpbnQgcnN1bSA9IHJzdC0+Z2V0KGwscik7CiAgICAgICAgICAgIHJldHVybiAobHN1bStyc3VtKSVtb2Q7CiAgICAgICAgfQogICAgfQp9OwoKbGwgYmlucG93KGxsIGJhc2UsIGludCBleHApIHsKICAgIGlmKGV4cCA9PSAwKSB7CiAgICAgICAgcmV0dXJuIDE7CiAgICB9ZWxzZSB7CiAgICAgICAgbGwgaGFsZiA9IGJpbnBvdyhiYXNlLGV4cC8yKTsKICAgICAgICBsbCBmdWxsID0gaGFsZipoYWxmJW1vZDsKICAgICAgICBpZihleHAlMikgewogICAgICAgICAgICBmdWxsID0gZnVsbCpiYXNlJW1vZDsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGZ1bGw7CiAgICB9Cn0KCmludCBtYWluKCkgewogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbygwKTsKICAgIGNpbi50aWUoTlVMTCk7CiAgICAKICAgIGNpbiA+PiB2WzBdID4+IHE7CiAgICAKICAgIGZvcihpbnQgaSA9IDA7IGkgPCBxOyBpKyspIHsKICAgICAgICBjaW4gPj4gcXN0b3JlW2ldWzBdID4+IHFzdG9yZVtpXVsxXTsKICAgICAgICAtLXFzdG9yZVtpXVsxXTsKICAgICAgICBpZihxc3RvcmVbaV1bMF0gPT0gMSkgewogICAgICAgICAgICBwYXJlbnRbbl0gPSBxc3RvcmVbaV1bMV07CiAgICAgICAgICAgIGNpbiA+PiB2W25dOwogICAgICAgICAgICBjaGlsZHJlbltwYXJlbnRbbl1dLnB1c2hfYmFjayhuKTsKICAgICAgICAgICAgcXN0b3JlW2ldWzFdID0gbjsKICAgICAgICAgICAgKytuOwogICAgICAgIH0KICAgIH0KICAgIAogICAgZGZzKDApOwogICAgCiAgICBzZWdtZW50X3RyZWUgKnN0X3Jvb3QgPSBuZXcgc2VnbWVudF90cmVlKDAsbi0xKTsKICAgIHN0X3Jvb3QtPnNldCgwLHZbMF0pOwogICAgCiAgICBmb3IoaW50IGkgPSAwOyBpIDwgcTsgaSsrKSB7CiAgICAgICAgaW50IHggPSBxc3RvcmVbaV1bMV07CiAgICAgICAgaWYocXN0b3JlW2ldWzBdID09IDEpIHsKICAgICAgICAgICAgaW50IHBhciA9IHBhcmVudFt4XTsKICAgICAgICAgICAgaW50IGxiID0gYm91bmRzW3Bhcl1bMF0sIHJiID0gYm91bmRzW3Bhcl1bMV07CiAgICAgICAgICAgIGludCBjdXJjaGlsZHJlbiA9ICsrYWN0aXZlY2hpbGRyZW5bcGFyXTsKICAgICAgICAgICAgaW50IG11bHQgPSBiaW5wb3coY3VyY2hpbGRyZW4sbW9kLTIpKihjdXJjaGlsZHJlbisxKSVtb2Q7CiAgICAgICAgICAgIHN0X3Jvb3QtPnJtdWx0KGxiLHJiLG11bHQpOwogICAgICAgICAgICAKICAgICAgICAgICAgaW50IHBhcm11bHRmYWN0b3IgPSBzdF9yb290LT5nZXQobGIsbGIpKmJpbnBvdyh2W3Bhcl0sbW9kLTIpJW1vZDsKICAgICAgICAgICAgaW50IGNoaWxkdmFsID0gbGwocGFybXVsdGZhY3Rvcikqdlt4XSVtb2Q7CiAgICAgICAgICAgIHN0X3Jvb3QtPnNldChib3VuZHNbeF1bMF0sY2hpbGR2YWwpOwogICAgICAgIH1lbHNlIHsKICAgICAgICAgICAgaW50IHJvb3RyZXMgPSBzdF9yb290LT5nZXQoYm91bmRzW3hdWzBdLGJvdW5kc1t4XVsxXSk7CiAgICAgICAgICAgIGludCBzY2FsZSA9IDE7CiAgICAgICAgICAgIGlmKHggPiAwKSB7CiAgICAgICAgICAgICAgICBzY2FsZSA9IHN0X3Jvb3QtPmdldChib3VuZHNbcGFyZW50W3hdXVswXSxib3VuZHNbcGFyZW50W3hdXVswXSkKICAgICAgICAgICAgICAgICAgICAgICAgICAgICpiaW5wb3codltwYXJlbnRbeF1dLG1vZC0yKSVtb2Q7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaW50IHJlcyA9IHJvb3RyZXMqYmlucG93KHNjYWxlLG1vZC0yKSVtb2Q7CiAgICAgICAgICAgIGNvdXQgPDwgcmVzIDw8ICdcbic7CiAgICAgICAgfQogICAgfQogICAgCiAgICByZXR1cm4gMDsKfQo=