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;
struct Node {
  string base_name;
  char op;
  int a, b;
  bool operator==(Node o) {
    return base_name == o.base_name && op == o.op && a == o.a && b == o.b;
  }
  void dump() {
    if (base_name.size())
      cout << base_name << endl;
    else
      cout << a << ' ' << op << ' ' << b << endl;
  }
};
vector<Node> term;
set<string> used;
string genName() {
  static int nextTry = 0;
  string s;
  do {
    s = "";
    int n = nextTry++;
    for (int i = 0; i < 4; i++) {
      s += char(n % 26 + 'a');
      n /= 26;
    }
  } while (used.count(s));
  used.insert(s);
  return s;
}
vector<string> ans;
string done[5000];
string dfs(int p, int last = 1) {
  if (done[p].size()) return done[p];
  if (term[p].base_name.empty()) {
    string a = dfs(term[p].a, 0);
    string b = dfs(term[p].b, 0);
    string name = last ? "res" : genName();
    ans.push_back(name + '=' + a + term[p].op + b);
    return done[p] = name;
  } else {
    if (last) {
      if (term[p].base_name != "res") ans.push_back("res=" + term[p].base_name);
    }
    return done[p] = term[p].base_name;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  map<string, int> mi;
  while (t--) {
    string line;
    cin >> line;
    vector<string> v;
    v.push_back("");
    char op = 0;
    for (char c : line) {
      if (c == '=')
        v.push_back("");
      else if (c == '$' || c == '^' || c == '#' || c == '&') {
        op = c;
        v.push_back("");
      } else
        v.back() += c;
    }
    for (int i = 1; i < v.size(); i++)
      if (!mi.count(v[i])) {
        mi[v[i]] = term.size();
        term.push_back({v[i]});
      }
    for (string s : v) used.insert(s);
    if (!op)
      mi[v[0]] = mi[v[1]];
    else {
      Node new_term = {"", op, mi[v[1]], mi[v[2]]};
      int i = find(term.begin(), term.end(), new_term) - term.begin();
      if (i == term.size()) {
        mi[v[0]] = term.size();
        term.push_back({new_term});
      } else {
        mi[v[0]] = i;
      }
    }
  }
  if (!mi.count("res")) {
    mi["res"] = term.size();
    term.push_back({"res"});
  }
  dfs(mi["res"]);
  cout << ans.size() << endl;
  for (string s : ans) cout << s << endl;
}