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;
typedef class Operation {
 public:
  char op;
  int x, y;
  Operation() : op('='), x(-1), y(-1) {}
  Operation(char op, int x, int y) : op(op), x(x), y(y) {}
  bool operator<(Operation b) const {
    if (op != b.op) return op < b.op;
    if (x != b.x) return x < b.x;
    return y < b.y;
  }
} Operation;
int n, m;
bool is_op[256];
map<string, int> val;
map<int, string> org;
vector<string> result;
map<int, Operation> G;
map<Operation, int> rG;
map<int, string> new_var;
void add(string x) {
  org[m] = x;
  val[x] = m++;
}
string make_new() {
  string s = "aaaa";
  do {
    s[rand() % 4] = rand() % 26 + 'a';
  } while (val.count(s));
  val[s] = -1;
  return s;
}
void dfs(int v, bool top = false) {
  if (org.count(v)) {
    if (top && org[v] != "res") {
      result.push_back("res=" + org[v]);
    }
    new_var[v] = org[v];
    return;
  }
  if (new_var.count(v)) {
    return;
  }
  Operation op = G[v];
  dfs(op.x);
  dfs(op.y);
  result.push_back((new_var[v] = (top ? ("res") : (make_new()))) + "=" +
                   new_var[op.x] + op.op + new_var[op.y]);
}
int main() {
  srand(233);
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  is_op['$'] = true;
  is_op['^'] = true;
  is_op['#'] = true;
  is_op['&'] = true;
  string str, a, b, c;
  cin >> n;
  while (n--) {
    cin >> str;
    int idx = str.find('='), idx1;
    a = str.substr(0, idx);
    for (idx1 = idx; idx < (signed)str.size() && !is_op[str[idx]]; idx++)
      ;
    if (idx == (signed)str.size()) {
      b = str.substr(idx1 + 1);
      if (!val.count(b)) {
        add(b);
      }
      val[a] = val[b];
    } else {
      b = str.substr(idx1 + 1, idx - idx1 - 1);
      c = str.substr(idx + 1);
      if (!val.count(b)) {
        add(b);
      }
      if (!val.count(c)) {
        add(c);
      }
      Operation op(str[idx], val[b], val[c]);
      if (!rG.count(op)) {
        rG[op] = m;
        G[m] = op;
        val[a] = m++;
      } else {
        val[a] = rG[op];
      }
    }
  }
  if (!val.count("res")) {
    puts("0");
    return 0;
  }
  dfs(val["res"], true);
  cout << result.size() << '\n';
  for (auto& s : result) {
    cout << s << '\n';
  }
  return 0;
}