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;
char s[100];
bool ops[256];
int relabel[N * 6];
int va[N * 6][2];
int typ[N * 6];
bool vis[N * 6], beres[N * 6];
string detail[N * 6];
map<string, int> ex;
map<pair<pair<int, int>, int>, int> rel;
vector<string> ans;
char usea;
int usev;
string nxtvar() {
  while (true) {
    string cur = string() + usea + to_string(usev);
    if (!ex.count(cur)) {
      ex.insert(make_pair(cur, 0));
      return cur;
    }
    if (++usev == 1000) {
      usev = 0;
      ++usea;
    }
  }
}
int strcnt;
int gid(const string& str) {
  auto it = ex.find(str);
  if (it != ex.end()) return it->second;
  ex.insert(make_pair(str, ++strcnt));
  detail[strcnt] = str;
  return strcnt;
}
int nid(const string& str) {
  detail[++strcnt] = str;
  return ex[str] = strcnt;
}
void dfs(int u) {
  if (vis[u]) return;
  vis[u] = true;
  if (typ[u] == 0) {
    relabel[u] = u;
    return;
  }
  if (typ[u] == -1) {
    if (beres[u]) {
      if (typ[va[u][0]]) {
        beres[va[u][0]] = true;
      } else {
        if (detail[va[u][0]] != "res") ans.push_back("res=" + detail[va[u][0]]);
        return;
      }
    }
    dfs(va[u][0]);
    relabel[u] = relabel[va[u][0]];
    return;
  }
  dfs(va[u][0]);
  dfs(va[u][1]);
  pair<pair<int, int>, int> spec(
      make_pair(relabel[va[u][0]], relabel[va[u][1]]), typ[u]);
  relabel[u] = u;
  if (!rel.count(spec)) {
    rel.insert(make_pair(spec, u));
    detail[u] = nxtvar();
    ans.push_back((beres[u] ? string("res") : detail[u]) + "=" +
                  detail[relabel[va[u][0]]] + char(typ[u]) +
                  detail[relabel[va[u][1]]]);
  } else
    relabel[u] = rel[spec];
}
int main() {
  usea = 'a';
  usev = 0;
  ops['$'] = true;
  ops['^'] = true;
  ops['#'] = true;
  ops['&'] = true;
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%s", s);
    char *p1 = s, *p2;
    while (*p1 != '=') ++p1;
    string a(s, p1);
    p2 = p1;
    while (!ops[*p2] && *p2) ++p2;
    if (ops[*p2]) {
      string b(p1 + 1, p2), c(p2 + 1);
      int bi = gid(b), ci = gid(c);
      int ai = nid(a);
      typ[ai] = *p2;
      va[ai][0] = bi;
      va[ai][1] = ci;
    } else {
      string b(p1 + 1);
      int bi = gid(b);
      int ai = nid(a);
      typ[ai] = -1;
      va[ai][0] = bi;
    }
  }
  int resi = gid("res");
  beres[resi] = true;
  dfs(resi);
  printf("%lu\n", ans.size());
  for (auto str : ans) puts(str.c_str());
  return 0;
}