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 N = 1010;
int tot = 0, ans = -1;
string lx, Ans;
struct op {
  int l, r;
  char ch;
};
set<string> all;
set<int> pd;
vector<string> ot;
vector<op> pt;
map<int, string> mk, to;
map<string, int> ys;
map<pair<pair<int, int>, char>, int> ds;
string zh(int x) {
  string s = "", t = "";
  for (; x; x /= 26) s += (char)(x % 26 + 'a');
  int tot = s.size();
  for (int i = 0; i <= tot - 1; ++i) t += s[tot - i - 1];
  return t;
}
string get(int x) {
  int be = x;
  if (x == ys["res"]) return "res";
  if (mk.find(x) != mk.end()) return mk[x];
  if (to.find(x) != to.end()) return to[x];
  for (;;) {
    if (all.find(zh(x)) == all.end()) {
      all.insert(zh(x));
      return to[be] = zh(x);
    }
    x++;
  }
}
void work(int x) {
  if (pt[x].ch == '.') return;
  if (pd.find(pt[x].l) == pd.end()) work(pt[x].l);
  if (pd.find(pt[x].r) == pd.end()) work(pt[x].r);
  ot.push_back(get(x) + "=" + get(pt[x].l) + pt[x].ch + get(pt[x].r));
  pd.insert(x);
}
int main() {
  int n;
  scanf("%d", &n);
  pt.push_back((op){-1, -1, '.'});
  for (int o = 1; o <= n; ++o) {
    cin >> lx;
    int p1 = -1, p2 = -1;
    int len = lx.size();
    for (int i = 0; i <= len - 1; ++i) {
      if (lx[i] == '=') p1 = i;
      if (lx[i] == '$' || lx[i] == '^' || lx[i] == '#' || lx[i] == '&') p2 = i;
    }
    if (p2 == -1) {
      string a = lx.substr(0, p1), b = lx.substr(p1 + 1, len - p1 - 1);
      if (a == b) continue;
      if (ys.find(b) == ys.end()) {
        ys[b] = ++tot;
        mk[tot] = b;
        all.insert(b);
        pt.push_back((op){-1, -1, '.'});
      }
      if (a == "res") {
        if (pt[ys[b]].ch == '.') ans = ys[b], Ans = mk[ys[b]];
      }
      ys[a] = ys[b];
    } else {
      string a = lx.substr(0, p1), b = lx.substr(p1 + 1, p2 - p1 - 1),
             c = lx.substr(p2 + 1, len - p2 - 1);
      if (ys.find(b) == ys.end()) {
        ys[b] = ++tot;
        mk[tot] = b;
        all.insert(b);
        pt.push_back((op){-1, -1, '.'});
      }
      if (ys.find(c) == ys.end()) {
        ys[c] = ++tot;
        mk[tot] = c;
        all.insert(c);
        pt.push_back((op){-1, -1, '.'});
      }
      int ib = ys[b], ic = ys[c];
      if (ds.find({{ib, ic}, lx[p2]}) == ds.end()) {
        ys[a] = ++tot;
        pt.push_back((op){ib, ic, lx[p2]});
        ds[{{ib, ic}, lx[p2]}] = ys[a];
      } else {
        ys[a] = ds[{{ib, ic}, lx[p2]}];
      }
    }
  }
  if (ys.find("res") == ys.end())
    printf("0\n");
  else if (ys["res"] == ans) {
    if (Ans == "res") return printf("0\n"), 0;
    printf("1\n");
    cout << "res=" << Ans << endl;
  } else {
    work(ys["res"]);
    int sz = ot.size();
    printf("%d\n", sz);
    for (int i = 0; i <= sz - 1; ++i) cout << ot[i] << endl;
  }
  return 0;
}