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 eng(chrono::high_resolution_clock::now().time_since_epoch().count() +
            reinterpret_cast<unsigned long>(new int) + *(new unsigned long));
struct node {
  node* left;
  node* right;
  unsigned h;
  char op;
};
map<string, node*> val;
map<unsigned, node*> unhasher;
map<unsigned, string> unval;
node* get_val(string var) {
  auto it = val.find(var);
  if (it == val.end()) {
    node* t = new node;
    t->left = t->right = nullptr;
    t->h = uniform_int_distribution<unsigned>(0, -1)(eng);
    t->op = 0;
    unval[t->h] = var;
    unhasher[t->h] = t;
    return val[var] = t;
  } else {
    return it->second;
  }
}
int used_var_names = 0;
string new_var_name() {
  int x = used_var_names++;
  return string("x") + to_string(x);
}
map<unsigned, string> var_allocator;
vector<string> sol;
void dfs(node* v, bool isRoot = false) {
  if (!v) return;
  if (var_allocator.count(v->h)) {
    return;
  }
  if (v->op == 0) {
    if (isRoot) {
      if (unval[v->h] != "res") sol.push_back("res=" + unval[v->h]);
    }
    var_allocator[v->h] = unval[v->h];
    return;
  }
  dfs(v->left);
  dfs(v->right);
  string lhs;
  if (isRoot) {
    lhs = "res";
  } else {
    lhs = new_var_name();
  }
  var_allocator[v->h] = lhs;
  sol.push_back(lhs + '=' + var_allocator[v->left->h] + v->op +
                var_allocator[v->right->h]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cerr.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int eq = s.find('=');
    string lhs = s.substr(0, eq);
    string rhs = s.substr(eq + 1);
    string op1, op2;
    char op = 0;
    for (int i = 0; i < (int)rhs.size(); i++) {
      if (!isalnum(rhs[i])) {
        op = rhs[i];
        op1 = rhs.substr(0, i);
        op2 = rhs.substr(i + 1);
        break;
      }
    }
    if (op == 0) {
      if (lhs == rhs) continue;
      val[lhs] = get_val(rhs);
    } else {
      auto v1 = get_val(op1);
      auto v2 = get_val(op2);
      auto nn = new node;
      nn->left = v1;
      nn->right = v2;
      nn->h = hash<string>()(string("I'm a SaLtY!") + to_string(v1->h) + op +
                             to_string(v2->h) + "~boY!!!");
      nn->op = op;
      unhasher[nn->h] = nn;
      val[lhs] = nn;
    }
  }
  if (val.count("res")) {
    dfs(val["res"], true);
    cout << sol.size() << '\n';
    for (string s : sol) cout << s << '\n';
  } else {
    cout << "0\n";
  }
}