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;
map<string, string> var, form, val;
set<string> us;
vector<string> ans;
void dfs(string name) {
  us.insert(name);
  string va = var[name];
  for (int a = 0; a < va.size(); a++) {
    if (va[a] == '$' or va[a] == '^' or va[a] == '#' or va[a] == '&') {
      string l = va.substr(0, a), r = va.substr(a + 1, va.size() - 1 - a);
      if (us.find(l) == us.end()) dfs(l);
      if (us.find(r) == us.end()) dfs(r);
      ans.push_back(name + "=" + va);
      break;
    }
  }
}
int yk = 0;
string new_var() {
  while (1) {
    int x = yk;
    string cu;
    for (int i = 0; i < 4; i++) {
      cu.push_back('a' + x % 26), x /= 26;
    }
    if (var.find(cu) == var.end())
      return cu;
    else
      yk++;
  }
}
int main() {
  int n;
  cin >> n;
  vector<string> sp[n];
  for (int a = 0; a < n; a++) {
    string str;
    cin >> str;
    int p1, p2 = -1;
    for (int b = 0; b < str.size(); b++) {
      if (str[b] == '=') p1 = b;
      if (str[b] == '$' or str[b] == '^' or str[b] == '#' or str[b] == '&')
        p2 = b;
    }
    string var1 = str.substr(0, p1), var2, var3, op;
    if (p2 != -1) {
      var2 = str.substr(p1 + 1, p2 - p1 - 1);
      op = str.substr(p2, 1);
      var3 = str.substr(p2 + 1);
    } else
      var2 = str.substr(p1 + 1);
    sp[a].push_back(var1), var[var1] = var1;
    sp[a].push_back(var2), var[var2] = var2;
    if (p2 != -1) {
      var[var3] = var3;
      sp[a].push_back(op), sp[a].push_back(var3);
    }
  }
  var["res"] = "res";
  for (auto it = var.begin(); it != var.end(); it++) {
    string cu = (*it).first;
    form[cu] = cu, val[cu] = cu;
  }
  for (int a = 0; a < n; a++) {
    string lva = sp[a][0], rva;
    if (sp[a].size() == 2)
      rva = val[sp[a][1]];
    else {
      string f = val[sp[a][1]] + sp[a][2] + val[sp[a][3]];
      if (form.find(f) != form.end())
        rva = form[f];
      else {
        string nvar = new_var();
        var[nvar] = f, form[f] = nvar, val[nvar] = nvar;
        rva = nvar;
      }
    }
    val[lva] = rva;
  }
  if (val["res"] != "res") {
    string x = val["res"];
    int p = -1;
    for (int a = 0; a < var[x].size(); a++) {
      if (var[x][a] == '$' or var[x][a] == '^' or var[x][a] == '#' or
          var[x][a] == '&')
        p = a;
    }
    if (p == -1)
      ans.push_back("res=" + x);
    else {
      dfs(x);
      ans.back() = "res" + ans.back().substr(x.size());
    }
  }
  cout << ans.size() << "\n";
  for (int a = 0; a < ans.size(); a++) cout << ans[a] << "\n";
}