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>
using namespace std;
const int N = 1 << 10;
unordered_map<string, int> tok;
map<tuple<int, char, int>, int> op;
struct node {
  string nem;
  tuple<int, char, int> dep;
  bool leaf;
} T[4 * N];
bool seen[4 * N];
int lcnt;
ostringstream os;
void dfs(int at) {
  if (seen[at] || T[at].leaf) return;
  seen[at] = 1;
  int l, r;
  char o;
  tie(l, o, r) = T[at].dep;
  dfs(l);
  dfs(r);
  lcnt++;
  os << T[at].nem << '=' << T[l].nem << o << T[r].nem << '\n';
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  int tokcnt = 1;
  tok["res"] = 0;
  T[0].nem = "res";
  T[0].leaf = 1;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int d1 = s.find('=');
    int d2 = s.find_first_of("&^#$");
    if (d2 == string::npos) {
      string rhS = s.substr(d1 + 1);
      int rhs;
      if (tok.count(rhS))
        rhs = tok[rhS];
      else {
        rhs = tok[rhS] = tokcnt++;
        T[rhs].nem = rhS;
        T[rhs].leaf = 1;
      }
      string lhS = s.substr(0, d1);
      tok[lhS] = rhs;
    } else {
      string s1 = s.substr(d1 + 1, d2 - d1 - 1);
      string s2 = s.substr(d2 + 1);
      int i1, i2;
      if (tok.count(s1))
        i1 = tok[s1];
      else {
        i1 = tok[s1] = tokcnt++;
        T[i1].nem = s1;
        T[i1].leaf = 1;
      }
      if (tok.count(s2))
        i2 = tok[s2];
      else {
        i2 = tok[s2] = tokcnt++;
        T[i2].nem = s2;
        T[i2].leaf = 1;
      }
      tuple<int, char, int> o = {i1, s[d2], i2};
      int rhs;
      if (op.count(o))
        rhs = op[o];
      else {
        rhs = op[o] = tokcnt++;
        T[rhs].dep = o;
        T[rhs].leaf = 0;
      }
      string lhS = s.substr(0, d1);
      tok[lhS] = rhs;
    }
  }
  {
    char c1 = 'a';
    int cat = 100;
    for (int i = 0; i < tokcnt; i++) {
      if (T[i].nem.size()) continue;
      while (1) {
        string s = string(1, c1) + to_string(cat);
        if (++cat > 999) {
          c1++;
          cat = 100;
        }
        if (!tok.count(s)) {
          T[i].nem = s;
          break;
        }
      }
    }
  }
  int root = tok["res"];
  if (T[root].leaf) {
    if (T[root].nem == "res")
      cout << "0\n";
    else
      cout << "1\nres=" << T[root].nem << '\n';
    return 0;
  }
  T[root].nem = "res";
  dfs(root);
  cout << lcnt << '\n' << os.str();
}