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;
string ss, sl, sr, S, s;
const int N = 6005;
int T, cnt = 0, last = 0, tot, vis[N], lson[N], rson[N], tg[N];
map<pair<pair<int, int>, char>, int> a;
map<string, int> lst, use;
string name[N], ans[N];
char opt[N];
void dfs(int x) {
  if (vis[x]) return;
  vis[x] = 1;
  if (!lson[x]) return;
  dfs(lson[x]), dfs(rson[x]);
  ans[++tot] = name[x] + "=" + name[lson[x]] + opt[x] + name[rson[x]];
}
int get(string s) {
  if (lst[s]) return lst[s];
  lst[s] = ++cnt;
  name[cnt] = s;
  tg[cnt] = -1;
  return cnt;
}
void solve() {
  int id = 1;
  for (char i = 'a'; i <= 'z'; i++)
    for (char j = 'a'; j <= 'z'; j++)
      for (char k = 'a'; k <= 'z'; k++)
        for (char h = 'a'; h <= 'z'; h++) {
          s = "";
          s = s + i + j + k + h;
          if (use[s]) continue;
          while (tg[id] == -1 && id <= cnt) id++;
          name[id] = s;
          id++;
          if (id > cnt) return;
        }
}
int main() {
  scanf("%d", &T);
  a.clear(), use.clear(), lst.clear();
  use["res"] = 1;
  for (int tim = 1; tim <= T; tim++) {
    cin >> ss;
    int n = ss.size(), i = 0, isl, isr;
    for (s = ""; ss[i] != '='; i++) s = s + ss[i];
    for (sl = "", i++; i < n && (ss[i] != '#' && ss[i] != '&' && ss[i] != '^' &&
                                 ss[i] != '$');
         i++)
      sl = sl + ss[i];
    isl = get(sl);
    use[sl] = 1;
    if (i == n)
      lst[s] = isl;
    else {
      char ch = ss[i];
      for (sr = "", i++; i < n; i++) sr = sr + ss[i];
      isr = get(sr);
      use[sr] = 1;
      int now = a[make_pair(make_pair(isl, isr), ch)];
      if (now) {
        lst[s] = now;
        continue;
      }
      a[make_pair(make_pair(isl, isr), ch)] = ++cnt;
      lson[cnt] = isl, rson[cnt] = isr;
      lst[s] = cnt;
      opt[cnt] = ch;
    }
  }
  assert(cnt <= 3000);
  int rt = lst["res"];
  if (name[rt] == "res" || (!rt)) return puts("0");
  if (tg[rt] == -1) {
    puts("1");
    cout << "res=" << name[rt];
    return 0;
  }
  s = "";
  solve();
  name[rt] = "res";
  dfs(rt);
  printf("%d\n", tot);
  for (int i = 1; i <= tot; i++) cout << ans[i] << endl;
}