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;
const int maxn = 131072;
const long long INF = 1e18;
const int sqrtConst = 316;
const int alphabet = 26;
const long long mod = 998244353;
const long double pi = acos(-1);
struct Node {
  Node* l;
  Node* r;
  char op;
  string var;
};
void init_if_not_exist(map<string, Node*>& kek, const string& var) {
  if (kek.count(var)) return;
  Node* node = new Node();
  node->l = NULL;
  node->r = NULL;
  node->op = '\0';
  node->var = var;
  kek[var] = node;
}
vector<string> ops;
set<string> var_ids;
map<string, string> map2;
void dfs(Node* node, bool is_root = true) {
  if (node->l->op) {
    dfs(node->l, false);
    return;
  }
  if (node->r->op) {
    dfs(node->r, false);
    return;
  }
  string kek = node->l->var + node->op + node->r->var;
  if (!map2.count(kek)) {
    string var_id = *(var_ids.begin());
    var_ids.erase(var_id);
    if (is_root) {
      var_id = "res";
    }
    map2[kek] = var_id;
    ops.push_back(var_id + "=" + kek);
  }
  node->op = '\0';
  node->var = map2[kek];
}
void solve() {
  string var_id = "aaaa";
  for (int i = 0; i < 25 * 25 * 25 * 25; i++) {
    var_ids.insert(var_id);
    for (int j = var_id.size(); j >= 0; j--) {
      if (var_id[j] == 'z') {
        var_id[j] = 'a';
      } else {
        var_id[j]++;
        break;
      }
    }
  }
  int n;
  cin >> n;
  set<int> del_set{'$', '^', '#', '&'};
  map<string, Node*> var_vals;
  for (int i = 0; i < n; i++) {
    string cur;
    cin >> cur;
    int eq_pos = -1;
    int op_pos = -1;
    for (int i = 0; i < cur.size(); i++) {
      if (cur[i] == '=') {
        eq_pos = i;
      }
      if (del_set.count(cur[i])) {
        op_pos = i;
      }
    }
    if (op_pos == -1) {
      string lhs = cur.substr(0, eq_pos);
      string rhs = cur.substr(eq_pos + 1);
      init_if_not_exist(var_vals, rhs);
      var_vals[lhs] = var_vals[rhs];
    } else {
      string lhs = cur.substr(0, eq_pos);
      char op = cur[op_pos];
      string arg1 = cur.substr(eq_pos + 1, op_pos - (eq_pos + 1));
      string arg2 = cur.substr(op_pos + 1);
      init_if_not_exist(var_vals, arg1);
      init_if_not_exist(var_vals, arg2);
      Node* node = new Node();
      node->l = var_vals[arg1];
      node->r = var_vals[arg2];
      node->op = op;
      var_vals[lhs] = node;
    }
  }
  if (var_vals.count("res") == 0) {
    cout << 0;
    return;
  }
  Node* root = var_vals["res"];
  if (!root->op && root->var != "res") {
    cout << 1 << '\n';
    cout << "res=" << root->var << '\n';
  } else {
    while (root->op) {
      dfs(root);
    }
    cout << ops.size() << endl;
    for (auto it : ops) {
      cout << it << "\n";
    }
  }
}
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(6) << fixed;
  solve();
  return 0;
}