Problem: Let's analyze a program written on some strange programming language. The variables in this language have names consisting of 1 to 4 characters, and each character is a lowercase or an uppercase Latin letter, or a digit. There is an extra constraint that the first character should not be a digit.

There are four types of operations in the program, each denoted by one of the characters: $, ^, # or &.

Each line of the program has one of the following formats: 

  * <lvalue>=<rvalue>, where <lvalue> and <rvalue> are valid variable names; 
  * <lvalue>=<arg1><op><arg2>, where <lvalue>, <arg1> and <arg2> are valid variable names, and <op> is an operation character. 



The program is executed line-by-line, and the result of execution is stored in a variable having the name res. If res is never assigned in the program, then the result will be equal to the value of res before running the program.

Two programs are called equivalent if no matter which operations do characters $, ^, # and & denote (but, obviously, performing the same operation on the same arguments gives the same result) and which values do variables have before execution of program, the value of res after running the first program is equal to the value of res after running the second program (the programs are executed independently).

You are given a program consisting of n lines. Your task is to write a program consisting of minimum possible number of lines that is equivalent to the program you are given.

Input

The first line contains one integer n (1 ≤ n ≤ 1000) — the number of lines in the program.

Then n lines follow — the program itself. Each line corresponds to the format described in the statement and has no extra whitespaces.

Output

In the first line print k — the minimum number of lines in the equivalent program.

Then print k lines without any whitespaces — an equivalent program having exactly k lines, in the same format it is described in the statement.

Examples

Input


4
c=aa#bb
d12=c
res=c^d12
tmp=aa$c


Output


2
aaaa=aa#bb
res=aaaa^aaaa


Input


2
max=aaaa$bbbb
min=bbbb^aaaa


Output


0

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
inline unsigned long long gi() {
  unsigned long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) f ^= ch == '-', ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return f ? x : -x;
}
std::vector<int> vec[1010];
int s;
std::map<std::string, int> mmp;
std::map<std::string, unsigned long long> key;
std::vector<std::string> ANS;
unsigned long long Key[1010];
std::string a[1010], b[1010], c[1010];
char op[1010];
std::map<unsigned long long, std::string> calced;
std::set<std::string> used;
inline std::string newstr() {
  std::string ret("test");
  static char ran[] = "qwertyuiopasdfghjklzxcvbnm1234567890";
  while (1) {
    ret[0] = 'a' + rand() % 26;
    for (int i = 1; i < 4; ++i) ret[i] = ran[rand() % 36];
    if (used.find(ret) == used.end()) {
      used.insert(ret);
      break;
    }
  }
  return ret;
}
inline std::string solve(std::string res, int n) {
  if (mmp.find(res) == mmp.end()) return res;
  int p = mmp[res];
  auto it = std::lower_bound(vec[p].begin(), vec[p].end(), n);
  if (it == vec[p].begin()) return res;
  n = *--it;
  if (calced.find(Key[n]) != calced.end()) return calced[Key[n]];
  if (op[n] == '%')
    return calced[Key[n]] = solve(b[n], n);
  else {
    std::string ret = newstr();
    ANS.push_back(ret + '=' + solve(b[n], n) + op[n] + solve(c[n], n));
    return calced[Key[n]] = ret;
  }
}
inline unsigned long long calc(unsigned long long a, unsigned long long b,
                               char c) {
  return (a + c * 3131441) * (b + c * 2332424);
}
int main() {
  srand(time(NULL));
  int n = gi();
  for (int i = 1; i <= n; ++i) {
    std::string yyb;
    std::cin >> yyb;
    int j, p;
    for (j = p = 0; j < yyb.size(); ++j)
      if (yyb[j] == '=')
        p = j, a[i] = yyb.substr(0, j);
      else if (yyb[j] == '$' || yyb[j] == '^' || yyb[j] == '#' || yyb[j] == '&')
        b[i] = yyb.substr(p + 1, j - p - 1),
        c[i] = yyb.substr(j + 1, yyb.size() - j - 1), op[i] = yyb[j];
    if (!op[i]) op[i] = '%', b[i] = yyb.substr(p + 1, yyb.size() - p - 1);
    if (mmp.find(a[i]) == mmp.end()) mmp[a[i]] = ++s;
    if (key.find(b[i]) == key.end()) key[b[i]] = 1llu * rand() * rand();
    if (!c[i].empty() && key.find(c[i]) == key.end())
      key[c[i]] = 1llu * rand() * rand();
    if (op[i] == '%')
      key[a[i]] = key[b[i]];
    else
      key[a[i]] = calc(key[b[i]], key[c[i]], op[i]);
    Key[i] = key[a[i]];
    used.insert(a[i]);
    used.insert(b[i]);
    used.insert(c[i]);
    vec[mmp[a[i]]].push_back(i);
  }
  for (int i = 1; i <= s; ++i) std::sort(vec[i].begin(), vec[i].end());
  std::string r = solve("res", n + 1);
  if (r != "res") {
    for (int i = ANS.size() - 1; ~i; --i)
      if (~ANS[i].find(r)) {
        ANS[i].replace(0, r.size(), "res");
        goto ed;
      }
    ANS.push_back("res=" + r);
  ed:;
  }
  printf("%d\n", ANS.size());
  for (auto i : ANS) std::cout << i << std::endl;
  return 0;
}