// #pragma optimization_level 3
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include<bits/stdc++.h>

using namespace std;



#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define  MOD             1000000007
#define  sym(s)          s = "#" + s + "#";
#define  INF             1e18
#define  newl            cout<<"\n";
#define  pb              push_back
#define  ppb             pop_back
#define  mp              make_pair
#define  ff              first
#define  ss              second
#define  PI              3.141592653589793238462
#define  set_bits        __builtin_popcountll
#define  sz(x)           ((int)(x).size())
#define  all(x)          (x).begin(), (x).end()
#define  alll(x,n)       x+1, x+n+1
#define  foo(i,a,n)      for(ll i = (a); i <= n; i++)
#define  deb1(a)         cout<<a<<"\n";
#define  deb2(a,b)       cout<<a<<" "<<b<<"\n";
#define  deb3(a,b,c)     cout<<a<<" "<<b<<" "<<c<<"\n";
#define  deb4(a,b,c,d)   cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define  debp(a)         cout<<a.ff<<" "<<a.ss<<"\n";
#define  debv(a)         for(auto it: a)cout<<it<<" ";newl;
#define  debm(a)         for(auto it: a)cout<<"{"<<it.ff<<","<<it.ss<<"}, ";newl;
#define  deb1d(a,n)      foo(i,1,n)cout<<a[i]<<" ";newl;
#define  deb2d(a,n,m)    foo(i,1,n){foo(j,1,m){cout<<a[i][j]<<" ";}newl;}
const int  N          =  (int)2e+5 + 8;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;
// typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update > pbds; // find_by_order, order_of_key

#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif

void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(ld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}

template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
map<string,string> f,l;
map<string,ll> ct;
void removeDupWord(string str,vector<string> &v)
{
    istringstream ss(str);
    
    string word; 
    while (ss >> word) 
    {
        v.pb(word);
    }
}
void MAIN(ll tc) {
    #ifndef ONLINE_JUDGE
    freopen("Error.txt", "w", stderr);
    #endif
    l.clear();
    f.clear();
    ct.clear();
    int n; cin>>n;
    string s;getline(cin,s);
    vector<string> v;
    for(int i=0;i<n;i++){
        getline(cin,s);
        v.clear();
        removeDupWord(s,v);
    	if(v[1]=="="){
    		ct[v[0]]=ct[v[2]]+ct[v[4]];
    		string k=l[v[2]]+f[v[4]];
    		if(sz(f[v[2]])<3){
 				f[v[0]]=k.substr(0,min(sz(k),3));
 			}
 			else{
 				f[v[0]]=f[v[2]];
 			}
 			if(sz(l[v[4]])<3){
 				l[v[0]]=k.substr(max(sz(k)-3,0));
 			}
 			else{
 				l[v[0]]=l[v[4]];
 			}
 			// deb1(k)
 			ll res=0;
		    if(sz(k)>3){    		
		    	for(int i=0;i<=sz(k)-4;i++){
			    	if(k.substr(i,4)=="haha")res++;
		    	}
		    }
		    ct[v[0]]+=res;
    	}
    	else{
			ll res=0;
		    if(sz(v[2])>3){    		
		        l[v[0]]=v[2].substr(sz(v[2])-3);		        
		        f[v[0]]=v[2].substr(0,3);
		    	for(int i=0;i<=sz(v[2])-4;i++){
			    	if(v[2].substr(i,4)=="haha")res++;
		    	}
		    }
		    else{
		    	f[v[0]]=l[v[0]]=v[2];
		    }
		    ct[v[0]]=res;		    
    	}
    	// deb3(f[v[0]],l[v[0]],ct[v[0]])
    }
    deb1(ct[v[0]])
}
int main(){
    fastio();
    cout<<fixed; cout<<setprecision(10);

    int test__cases = 1;
    cin>>test__cases; 
    for(int i = 1; i <= test__cases; i++){
        MAIN(i);
    }
}
### Prompt

Your challenge is to write a Cpp solution to the following problem:

Polycarp came up with a new programming language. There are only two types of statements in it: 

  * "x := s": assign the variable named x the value s (where s is a string). For example, the statement var := hello assigns the variable named var the value hello. Note that s is the value of a string, not the name of a variable. Between the variable name, the := operator and the string contains exactly one space each.
  * "x = a + b": assign the variable named x the concatenation of values of two variables a and b. For example, if the program consists of three statements a := hello, b := world, c = a + b, then the variable c will contain the string helloworld. It is guaranteed that the program is correct and the variables a and b were previously defined. There is exactly one space between the variable names and the = and + operators. 



All variable names and strings only consist of lowercase letters of the English alphabet and do not exceed 5 characters.

The result of the program is the number of occurrences of string haha in the string that was written to the variable in the last statement.

Polycarp was very tired while inventing that language. He asks you to implement it. Your task is — for given program statements calculate the number of occurrences of string haha in the last assigned variable.

Input

The first line contains an integer t (1 ≤ t ≤ 10^3). Then t test cases follow.

The first line of each test case contains a single integer n (1 ≤ n ≤ 50) — the number of statements in the program. All variable names and strings are guaranteed to consist only of lowercase letters of the English alphabet and do not exceed 5 characters.

This is followed by n lines describing the statements in the format described above. It is guaranteed that the program is correct.

Output

For each set of input data, output the number of occurrences of the haha substring in the string that was written to the variable in the last statement.

Example

Input


4
6
a := h
b := aha
c = a + b
c = c + c
e = c + c
d = a + c
15
x := haha
x = x + x
x = x + x
x = x + x
x = x + x
x = x + x
x = x + x
x = x + x
x = x + x
x = x + x
x = x + x
x = x + x
x = x + x
x = x + x
x = x + x
1
haha := hah
5
haahh := aaaha
ahhhh = haahh + haahh
haahh = haahh + haahh
ahhhh = ahhhh + haahh
ahhaa = haahh + ahhhh


Output


3
32767
0
0

Note

In the first test case the resulting value of d is hhahahaha.

### Response

```cpp
// #pragma optimization_level 3
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include<bits/stdc++.h>

using namespace std;



#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define  MOD             1000000007
#define  sym(s)          s = "#" + s + "#";
#define  INF             1e18
#define  newl            cout<<"\n";
#define  pb              push_back
#define  ppb             pop_back
#define  mp              make_pair
#define  ff              first
#define  ss              second
#define  PI              3.141592653589793238462
#define  set_bits        __builtin_popcountll
#define  sz(x)           ((int)(x).size())
#define  all(x)          (x).begin(), (x).end()
#define  alll(x,n)       x+1, x+n+1
#define  foo(i,a,n)      for(ll i = (a); i <= n; i++)
#define  deb1(a)         cout<<a<<"\n";
#define  deb2(a,b)       cout<<a<<" "<<b<<"\n";
#define  deb3(a,b,c)     cout<<a<<" "<<b<<" "<<c<<"\n";
#define  deb4(a,b,c,d)   cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define  debp(a)         cout<<a.ff<<" "<<a.ss<<"\n";
#define  debv(a)         for(auto it: a)cout<<it<<" ";newl;
#define  debm(a)         for(auto it: a)cout<<"{"<<it.ff<<","<<it.ss<<"}, ";newl;
#define  deb1d(a,n)      foo(i,1,n)cout<<a[i]<<" ";newl;
#define  deb2d(a,n,m)    foo(i,1,n){foo(j,1,m){cout<<a[i][j]<<" ";}newl;}
const int  N          =  (int)2e+5 + 8;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;
// typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update > pbds; // find_by_order, order_of_key

#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif

void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(ld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}

template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
map<string,string> f,l;
map<string,ll> ct;
void removeDupWord(string str,vector<string> &v)
{
    istringstream ss(str);
    
    string word; 
    while (ss >> word) 
    {
        v.pb(word);
    }
}
void MAIN(ll tc) {
    #ifndef ONLINE_JUDGE
    freopen("Error.txt", "w", stderr);
    #endif
    l.clear();
    f.clear();
    ct.clear();
    int n; cin>>n;
    string s;getline(cin,s);
    vector<string> v;
    for(int i=0;i<n;i++){
        getline(cin,s);
        v.clear();
        removeDupWord(s,v);
    	if(v[1]=="="){
    		ct[v[0]]=ct[v[2]]+ct[v[4]];
    		string k=l[v[2]]+f[v[4]];
    		if(sz(f[v[2]])<3){
 				f[v[0]]=k.substr(0,min(sz(k),3));
 			}
 			else{
 				f[v[0]]=f[v[2]];
 			}
 			if(sz(l[v[4]])<3){
 				l[v[0]]=k.substr(max(sz(k)-3,0));
 			}
 			else{
 				l[v[0]]=l[v[4]];
 			}
 			// deb1(k)
 			ll res=0;
		    if(sz(k)>3){    		
		    	for(int i=0;i<=sz(k)-4;i++){
			    	if(k.substr(i,4)=="haha")res++;
		    	}
		    }
		    ct[v[0]]+=res;
    	}
    	else{
			ll res=0;
		    if(sz(v[2])>3){    		
		        l[v[0]]=v[2].substr(sz(v[2])-3);		        
		        f[v[0]]=v[2].substr(0,3);
		    	for(int i=0;i<=sz(v[2])-4;i++){
			    	if(v[2].substr(i,4)=="haha")res++;
		    	}
		    }
		    else{
		    	f[v[0]]=l[v[0]]=v[2];
		    }
		    ct[v[0]]=res;		    
    	}
    	// deb3(f[v[0]],l[v[0]],ct[v[0]])
    }
    deb1(ct[v[0]])
}
int main(){
    fastio();
    cout<<fixed; cout<<setprecision(10);

    int test__cases = 1;
    cin>>test__cases; 
    for(int i = 1; i <= test__cases; i++){
        MAIN(i);
    }
}
```