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;
using ll = long long;
using ld = long double;
map<string, int> cn;
map<vector<int>, int> gn;
const int N = 5001;
int tv[N], t1[N], t2[N], top[N], cs = 3005, fs = cs;
map<int, string> nc;
string ide = "aaaa", lop = "$^#&";
set<int> used;
int sadd(string s) {
  if (!cn.count(s)) {
    int sz = cn.size();
    cn[s] = sz;
    nc[sz] = s;
  }
  return cn[s];
}
string genn(int num) {
  if (nc.count(num)) return nc[num];
  while (cn.count(ide)) {
    for (int i = 3; i >= 0; i--) {
      if (ide[i] == 'z')
        ide[i] = 'a';
      else {
        ide[i]++;
        break;
      }
    }
  }
  cn[ide] = num;
  nc[num] = ide;
  return ide;
}
vector<string> ans;
void dfs(int v) {
  if (v < fs || used.count(v)) return;
  used.insert(v);
  dfs(t1[v]);
  dfs(t2[v]);
  ans.push_back(genn(v) + "=" + genn(t1[v]) + lop[top[v]] + genn(t2[v]));
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  string s;
  map<char, int> mp = {{'$', 0}, {'^', 1}, {'#', 2}, {'&', 3}};
  cn["res"] = 0;
  nc[0] = "res";
  for (int i = 0; i < (cs); i++) tv[i] = i;
  for (int i = 0; i < (n); i++) {
    cin >> s;
    vector<string> ts(3);
    int op;
    int p = 0;
    for (char c : s) {
      if (c == '=')
        p++;
      else if (mp.count(c)) {
        op = mp[c];
        p++;
      } else
        ts[p].push_back(c);
    }
    if (p == 1) {
      int n1 = sadd(ts[0]), n2 = tv[sadd(ts[1])];
      tv[n1] = n2;
    } else {
      int n1 = sadd(ts[0]), n2 = tv[sadd(ts[1])], n3 = tv[sadd(ts[2])];
      vector<int> di = {n2, n3, op};
      if (!gn.count(di)) {
        t1[cs] = n2;
        t2[cs] = n3;
        top[cs] = op;
        gn[di] = cs++;
      }
      tv[n1] = gn[di];
    }
  }
  if (tv[0] >= fs) nc[tv[0]] = "res";
  dfs(tv[0]);
  if (tv[0] < fs && tv[0] != 0) ans.push_back("res=" + genn(tv[0]));
  cout << ans.size() << '\n';
  for (string rs : ans) cout << rs << '\n';
}