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;
bool debug = true;
template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2> ptt) {
  os << ptt.first << "," << ptt.second;
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vt) {
  os << "{";
  for (int i = 0; i < vt.size(); i++) {
    os << vt[i] << " ";
  }
  os << "}";
  return os;
}
int n;
string code[1005];
struct Node {
  long long l, r;
  char op;
  Node() {}
  Node(long long a, long long b, char c) {
    l = a;
    r = b;
    op = c;
  }
};
map<string, long long> val;
map<long long, string> hsh2var;
map<long long, Node> node;
map<long long, string> name;
set<string> inUse;
const long long p = 999983;
long long getHash(string& r) {
  long long hsh = 0;
  for (int i = 0; i < r.size(); i++) {
    hsh = hsh * p + r[i];
  }
  return hsh;
}
long long getVal(string& r) {
  if (val.count(r)) {
    return val[r];
  } else {
    long long hsh = getHash(r);
    val[r] = hsh;
    if (hsh2var.count(hsh)) {
      assert(false);
    }
    hsh2var[hsh] = r;
    inUse.insert(r);
    return hsh;
  }
}
string curName = "aaaa";
string getName() {
st:
  int p = 3;
  while (true) {
    if (p == -1) {
      assert(false);
    }
    curName[p]++;
    if (curName[p] > 'z') {
      curName[p] = 'a';
      p--;
    } else {
      break;
    }
  }
  if (!inUse.count(curName)) {
    return curName;
  } else {
    goto st;
  }
}
vector<string> ans;
string dfs(long long pos, bool isRoot) {
  if (!node.count(pos)) {
    return hsh2var[pos];
  }
  if (name.count(pos)) {
    return name[pos];
  }
  string lp = dfs(node[pos].l, false);
  string rp = dfs(node[pos].r, false);
  string nm = (isRoot ? "res" : getName());
  ans.push_back(nm + "=" + lp + node[pos].op + rp);
  name[pos] = nm;
  return nm;
}
string readVar(string& s, int& po) {
  string ans = "";
  while (po < s.size()) {
    ans += s[po];
    po++;
    if (!isalpha(s[po]) && !isdigit(s[po])) {
      return ans;
    }
  }
  return ans;
}
long long mixHash(long long h1, long long h2, char op) {
  return h1 * 1000000007 + op * 998244353 + h2;
}
int main(int argc, char* argv[]) {
  ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> code[i];
  }
  for (int i = 0; i < n; i++) {
    int pointer = 0;
    string lv = readVar(code[i], pointer);
    pointer++;
    string rv = readVar(code[i], pointer);
    if (pointer == code[i].size()) {
      val[lv] = getVal(rv);
    } else {
      char op = code[i][pointer];
      pointer++;
      string rv2 = readVar(code[i], pointer);
      long long v1 = getVal(rv);
      long long v2 = getVal(rv2);
      val[lv] = mixHash(v1, v2, op);
      node[val[lv]] = Node(v1, v2, op);
    }
  }
  if (!val.count("res")) {
    cout << "0" << endl;
    return 0;
  }
  string omg = dfs(val["res"], true);
  if (omg != "res") {
    cout << "1" << endl;
    cout << "res=" << omg << endl;
    return 0;
  }
  cout << ans.size() << endl;
  for (string x : ans) {
    cout << x << endl;
  }
  return 0;
}