#include <bits/stdc++.h>   using namespace std;   const int INF = (int)2E9;   const long long LINF = (long long)9E18;   const long double PI = acos(-1.0);   const long double EPS = 1E-11;   template <typename T>   inline T sqr(const T x) {     return x * x;   }   template <typename T>   T gcd(T a, T b) {     return (b == 0) ? a : gcd(b, a % b);   }   template <typename T>   T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   template <typename T>   T mod(T a, T b) {     a %= b;     if (a < 0) a += b;     return a;   }   template <typename T>   inline T rad(const T x) {     return x * PI / 180;   }   template <typename T>   inline string toString(T x) {     ostringstream oss;     oss << x;     return oss.str();   }   inline long long toInt(const string& st) {     istringstream istringstream(st);     long long x;     istringstream >> x;     return x;   }   inline long double toDouble(const string& st) {     istringstream istringstream(st);     long double x;     istringstream >> x;     return x;   }   inline string toLower(string st) {     for (int i = 0; i < (((int)(st).size())); ++i) st[i] = tolower(st[i]);     return st;   }   inline string toUpper(string st) {     for (int i = 0; i < (((int)(st).size())); ++i) st[i] = toupper(st[i]);     return st;   }   const int dx[] = {-1, 0, 1, 0};   const int dy[] = {0, 1, 0, -1};   int DEBUG = false;   const char DEBUG_PARAM[] =  __LOCAL_TESTING ;   const int MAXCLOCK = 100;   int aClock[MAXCLOCK], mClock[MAXCLOCK], nClock = 0, iClock = 0;   inline void tick(int maxTime = 10000) {     if (DEBUG) {       mClock[nClock] = maxTime;       aClock[nClock++] = clock();     }   }   inline void untick(string name =  Execution Time ) {     if (DEBUG) {       int numClock = clock() - aClock[--nClock];       cout <<  @   << name <<  : [             << (int)((double)(numClock) / CLOCKS_PER_SEC * 1000) <<   ms] ;       if (numClock > (int)(mClock[nClock]))         cout <<   [TLE] ;       else if (numClock > (int)(mClock[nClock] * 0.9))         cout <<   [almost TLE] ;       cout << endl;     }   }   const char IN[] =  _.in ;   const char OUT[] =  _.out ;   int ntest = 1, test = 1;   int n;   map<string, string> type;   pair<int, int> findDefRef(string w) {     int d = 0, r = 0;     while (d < ((int)(w).size()) && w[d] ==  & ) d++;     while (r < ((int)(w).size()) && w[((int)(w).size()) - r - 1] ==  * ) r++;     return make_pair(d, r);   }   string removeDefRef(string w) {     pair<int, int> tmp = findDefRef(w);     return w.substr(tmp.first, ((int)(w).size()) - tmp.first - tmp.second);   }   string findType(string original, int def, int ref) {     if (type.count(original) == 0) {       return  errtype ;     }     string nowType = type[original];     if (nowType ==  errtype ) {       return nowType;     }     pair<int, int> tmp = findDefRef(nowType);     nowType = removeDefRef(nowType);     def += tmp.first, ref += tmp.second;     if (def > ref) {       return  errtype ;     } else {       ref -= def;       def = 0;     }     for (int i = 0; i < (ref); ++i) nowType = nowType +  * ;     return nowType;   }   inline void run() {     type[ void ] =  void ;     type[ errtype ] =  errtype ;     for (test = 1; test <= ntest; ++test) {       tick((int)2E3);       cin >> n;       string command, a, b;       pair<int, int> tmp;       int def, ref;       for (int i = (1); i <= (n); ++i) {         cin >> command;         if (command ==  typedef ) {           cin >> a >> b;           tmp = findDefRef(a);           def = tmp.first, ref = tmp.second;           a = removeDefRef(a);           type[b] = findType(a, def, ref);         } else {           cin >> a;           tmp = findDefRef(a);           def = tmp.first, ref = tmp.second;           a = removeDefRef(a);           cout << findType(a, def, ref) << endl;         }       }       untick( #  + toString(test));     }   }   int main(int argc, char* argv[]) {     if (argc > 1 && strcmp(argv[1], DEBUG_PARAM) == 0) {       DEBUG = true;     }     if (DEBUG) {       tick((int)1E4);       freopen(IN,  r , stdin);     }     run();     if (DEBUG) {       untick( TOTAL );     }     return 0;   }