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>
const int inf = (1ll << 30) - 1;
const int maxn = (int)1e5 + 10;
const int mod = (int)1e9 + 7;
using namespace std;
string second;
vector<int> g[100100];
char OP[100100];
map<string, int> id;
map<pair<pair<int, int>, char>, int> comp_id;
int sz;
int N;
bool op(char c) {
  return c == '$' || c == '^' || c == '#' || c == '&' || c == '=';
}
string h[100100];
int was[100100];
int ID[100100];
int get_val(string x) {
  if (id.count(x) == 0) {
    id[x] = sz;
    h[sz] = x;
    sz++;
  }
  return id[x];
}
int ind;
vector<string> G, ans;
string gen_string() {
  while (id.count(G[ind])) ind++;
  return G[ind];
}
int dfs(int v, int need = 1) {
  if (was[v]) return ID[v];
  if (g[v].size() == 0) {
    return v;
  }
  int x = dfs(g[v][0], 0);
  int y = dfs(g[v][1], 0);
  was[v] = 1;
  if (comp_id.count(make_pair(make_pair(x, y), OP[v])) == 0) {
    string t = need ? "res" : gen_string();
    int u = get_val(t);
    ID[v] = u;
    ans.push_back(t + "=" + h[x] + OP[v] + h[y]);
    comp_id[make_pair(make_pair(x, y), OP[v])] = u;
  }
  return ID[v] = comp_id[make_pair(make_pair(x, y), OP[v])];
}
void precalc(string d) {
  if (G.size() > 200200) return;
  if (d.size() == 4) {
    G.push_back(d);
    return;
  }
  for (char c = 'a'; c <= 'z'; c++) {
    precalc(d + c);
  }
}
void solve() {
  cin >> N;
  get_val("res");
  for (int i = 0; i < N; i++) {
    string second;
    cin >> second;
    int j = 0;
    vector<string> d;
    while (j < second.size()) {
      string x;
      while (j < second.size() && !op(second[j])) {
        x += second[j];
        j++;
      }
      d.push_back(x);
      j++;
    }
    if (d.size() == 2) {
      id[d[0]] = get_val(d[1]);
    } else {
      int cur_id = sz;
      sz++;
      OP[cur_id] = second[d[0].size() + d[1].size() + 1];
      int x = get_val(d[1]);
      int y = get_val(d[2]);
      id[d[0]] = cur_id;
      g[cur_id].push_back(x);
      g[cur_id].push_back(y);
    }
  }
  dfs(id["res"]);
  if (ans.size() == 0 && id["res"] != 0) {
    ans.push_back("res=" + h[id["res"]]);
  }
  cout << ans.size() << "\n";
  for (int i = 0; i < ans.size(); i++) cout << ans[i] << "\n";
}
int main() {
  precalc("");
  int t = 1;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}