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;
template <typename T>
void clear(T& t) {
  t.clear();
}
template <typename T, typename... Ts>
void clear(T& t, Ts&... ts) {
  t.clear();
  clear(ts...);
}
template <typename T>
void clearAndResize(int n, T& t) {
  t.clear();
  t.resize(n);
}
template <typename T, typename... Ts>
void clearAndResize(int n, T& t, Ts&... ts) {
  t.clear();
  t.resize(n);
  clearAndResize(n, ts...);
}
template <class T>
ostream& operator<<(ostream& o, const vector<T>& v) {
  for (auto a : v) o << a << " ";
  return o;
}
template <class T, class U>
ostream& operator<<(ostream& o, const pair<T, U>& p) {
  o << "(" << p.first << ", " << p.second << ") ";
  return o;
}
vector<string> names;
int nam_ct = 0;
map<string, string> m;
map<string, string> m2;
void relabel(string& str) {
  m[str] = names[nam_ct++];
  str = m[str];
}
void updateName(string& str) {
  if (m.count(str) == 0) {
    m[str] = str;
  } else
    str = m[str];
}
vector<vector<string> > tab;
vector<string> ans;
void solve(string last) {
  set<string> used;
  used.insert(last);
  for (int i = tab.size() - 1; i >= 0; i--) {
    if (used.find(tab[i][0]) != used.end()) {
      used.erase(tab[i][0]);
      ans.push_back(tab[i][0] + "=" + tab[i][1] + tab[i][2] + tab[i][3]);
      used.insert(tab[i][1]);
      used.insert(tab[i][3]);
    }
  }
}
int32_t main(int argv, char** argc) {
  ios::sync_with_stdio(false);
  for (int i = 0; i < 26; i++) {
    for (int j = 0; j < 26; j++) {
      for (int k = 0; k < 26; k++) {
        names.push_back("   ");
        names.back()[0] = i + 'a';
        names.back()[1] = j + 'a';
        names.back()[2] = k + 'a';
        if (names.back() == "res") names.back() = "xdxd";
      }
    }
  }
  int n;
  cin >> n;
  const string opp = "#^$&";
  for (int i = 0; i < n; i++) {
    string comm;
    cin >> comm;
    string lval, rval1, rval2;
    char op = 0;
    int p = 0;
    for (int i = 0; i < comm.size(); i++) {
      if (comm[i] == '=') {
        lval = comm.substr(0, i);
        p = i + 1;
      }
      for (auto o : opp) {
        if (comm[i] == o) {
          op = o;
          rval1 = comm.substr(p, i - p);
          rval2 = comm.substr(i + 1);
          break;
        }
      }
      if (op != 0) break;
    }
    if (op == 0) {
      rval1 = comm.substr(p);
      updateName(rval1);
      m[lval] = rval1;
    } else {
      updateName(rval1);
      updateName(rval2);
      if (m2.count(rval1 + op + rval2) != 0)
        m[lval] = m2[rval1 + op + rval2];
      else {
        relabel(lval);
        m2[rval1 + op + rval2] = lval;
        tab.push_back(vector<string>(4));
        string ss;
        ss += op;
        tab.back() = {lval, rval1, ss, rval2};
      }
    }
  }
  for (auto& a : tab) {
    if (a[0] == m["res"]) a[0] = "res";
    if (a[1] == m["res"]) a[1] = "res";
    if (a[3] == m["res"]) a[3] = "res";
  }
  solve("res");
  if (ans.size() == 0)
    if (m["res"] != "" && m["res"] != "res") ans.push_back("res=" + m["res"]);
  cout << ans.size() << endl;
  for (int i = ans.size() - 1; i >= 0; i--) cout << ans[i] << "\n";
}