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;
mt19937 rng(uint64_t(new char));
map<string, tuple<string, string, char>> expr;
map<tuple<string, string, char>, string> vstd;
map<string, string> eq, mp;
vector<string> ans;
void dfs(const string& u) {
  if (!expr.count(u)) {
    if (expr.count(eq[u])) {
      expr[u] = expr[eq[u]];
    } else if (eq[u] != u) {
      ans.push_back(u + '=' + eq[u]);
      return;
    } else
      return;
  }
  auto [arg1, arg2, op] = expr[u];
  expr.erase(u);
  dfs(arg1);
  dfs(arg2);
  ans.push_back(u + '=' + arg1 + op + arg2);
}
string newVar() {
  string res = "";
  for (int i = 0; i < 4; ++i) {
    res += char('a' + rng() % 26);
  }
  if (eq.count(res)) return newVar();
  return res;
}
void chk(string& s) {
  if (mp.count(s)) {
    s = mp[s];
  }
  if (!eq.count(s)) {
    eq[s] = s;
  } else {
    s = eq[s];
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  eq["res"] = "res";
  while (n--) {
    string s;
    cin >> s;
    int ndxE = find(s.begin(), s.end(), '=') - s.begin();
    string lval = s.substr(0, ndxE);
    string rval = s.substr(ndxE + 1);
    string arg1 = "", arg2 = "";
    char op = 0;
    for (char c : "$^#&") {
      int ndxO = find(rval.begin(), rval.end(), c) - rval.begin();
      if (ndxO < int(rval.size())) {
        arg1 = rval.substr(0, ndxO);
        arg2 = rval.substr(ndxO + 1);
        op = c;
      }
    }
    if (op) {
      chk(arg1);
      chk(arg2);
    } else {
      chk(rval);
    }
    if (eq.count(lval)) {
      mp[lval] = newVar();
      lval = mp[lval];
    }
    if (op) {
      auto res = make_tuple(arg1, arg2, op);
      if (vstd.count(res)) {
        eq[lval] = vstd[res];
      } else {
        eq[lval] = lval;
        expr[lval] = res;
        vstd[res] = lval;
      }
    } else {
      eq[lval] = rval;
    }
  }
  if (mp.count("res")) {
    string oth = mp["res"];
    eq["res"] = eq[oth];
    if (eq["res"] == oth) {
      eq["res"] = "res";
    }
    if (expr.count(oth)) {
      expr["res"] = expr[oth];
    }
  }
  dfs("res");
  cout << ans.size() << '\n';
  for (auto& s : ans) {
    cout << s << '\n';
  }
}