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 = 4087;
pair<string, pair<int, int>> var[N];
map<pair<string, pair<int, int>>, int> ivar;
int vn = 1;
map<string, int> cur;
vector<string> ans;
string name[N];
set<string> used;
int tp, rt;
int get(string s) {
  if (!cur.count(s)) var[cur[s] = vn++] = {s, {0, 0}};
  return cur[s];
}
int get_var(pair<string, pair<int, int>> p) {
  if (!ivar.count(p)) var[ivar[p] = vn++] = p;
  return ivar[p];
}
string dec(int x) {
  string ret;
  for (int i = 0; i < 4; ++i) ret += char(x % 26 + 'a'), x /= 26;
  return ret;
}
string nxt_name() {
  while (used.count(dec(tp))) tp++;
  return dec(tp++);
}
void go(int u) {
  if (name[u].size()) return;
  int l, r;
  tie(l, r) = var[u].second;
  if (l) {
    go(l);
    go(r);
    name[u] = u == rt ? "res" : nxt_name();
    ans.push_back(name[u] + "=" + name[l] + var[u].first + name[r]);
  } else {
    name[u] = var[u].first;
  }
}
int main() {
  int n;
  cin >> n;
  while (n--) {
    string s, x, y, z;
    cin >> s;
    char op = 0;
    for (int i = 0; i < s.size(); ++i)
      if (!(isalpha(s[i]) || isdigit(s[i]))) op = s[i], s[i] = ' ';
    stringstream ss(s);
    if (op == '=') {
      ss >> x >> y;
      int a = get(y);
      cur[x] = a;
      used.insert(x);
      used.insert(y);
    } else {
      ss >> x >> y >> z;
      int a = get(y);
      int b = get(z);
      auto p = make_pair(string{op}, make_pair(a, b));
      cur[x] = get_var(p);
      used.insert(x);
      used.insert(y);
      used.insert(z);
    }
  }
  rt = cur["res"];
  if (!rt) {
    cout << "0\n";
    return 0;
  }
  go(rt);
  if (ans.size()) {
    cout << ans.size() << endl;
    for (auto s : ans) cout << s << '\n';
  } else if (var[rt].first != "res") {
    cout << "1\nres=" << var[rt].first << endl;
  } else {
    cout << "0\n";
  }
}