#import<bits/stdc++.h>
#define a first
#define b second
#define c(s);else if(x.a==s)
#define e(n)(n=regex_replace(n,q,"$1")).empty()
#define f(n)for(;getline(cin,n),e(n););
#define i p.top().a
#define j!p.empty()
#define w,back_inserter
using namespace std;using g=string;using h=istream_iterator<g>;using s=vector<g>;using A=array<g,3>;using t=pair<pair<long,A>,s>;map<g,A>m;map<g,long>n;stack<t>p;regex q("^ *(.*?) *(#.*)?$");main(){bool z;for(g W,X,Y,Z;getline(cin,W);)if(!e(W))for(p.push(t{{0,{{W,"",""}}},{}});z=j;){pair<g,s>x;istringstream S(i.b[i.a]);S>>x.a;copy(h(S),h()w(x.b));s o;transform(&x.b[0],&*end(x.b)w(o),[](g y){int v=atoi(&y[0]);return v>0?p.top().b[v-1]:y;});if(0)c("")c("p")cout<<o[0]<<" = "<<n[o[0]]<<'\n'c("i")n[o[0]]++c("d")n[o[0]]-=z=n[o[0]]c("a"){f(X)f(Y)f(Z)m.insert(make_pair(o[0],A{{X,Y,Z}}));}else{p.push(t{{0,m[x.a]},o});continue;}while(j&&i.a)p.pop();j?i.a-=~!z:0;}}
I2ltcG9ydDxiaXRzL3N0ZGMrKy5oPgojZGVmaW5lIGEgZmlyc3QKI2RlZmluZSBiIHNlY29uZAojZGVmaW5lIGMocyk7ZWxzZSBpZih4LmE9PXMpCiNkZWZpbmUgZShuKShuPXJlZ2V4X3JlcGxhY2UobixxLCIkMSIpKS5lbXB0eSgpCiNkZWZpbmUgZihuKWZvcig7Z2V0bGluZShjaW4sbiksZShuKTspOwojZGVmaW5lIGkgcC50b3AoKS5hCiNkZWZpbmUgaiFwLmVtcHR5KCkKI2RlZmluZSB3LGJhY2tfaW5zZXJ0ZXIKdXNpbmcgbmFtZXNwYWNlIHN0ZDt1c2luZyBnPXN0cmluZzt1c2luZyBoPWlzdHJlYW1faXRlcmF0b3I8Zz47dXNpbmcgcz12ZWN0b3I8Zz47dXNpbmcgQT1hcnJheTxnLDM+O3VzaW5nIHQ9cGFpcjxwYWl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