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;
#pragma GCC optimize("O3")
using pii = pair<int, int>;
using vi = vector<int>;
using ll = long long;
const int N = 3e3;
int nxt = 0, rval;
vector<string> res;
map<string, int> num;
string val[N], back[N];
map<string, string> pro;
const string op = "$^#&";
void split(const string &s, string &l, string &r, string &o, bool &f) {
  for (int i = int(0); i < int(int((s).size())); i++)
    for (int j = int(0); j < int(4); j++)
      if (s[i] == op[j])
        o = op[j], l = s.substr(0, i), r = s.substr(i + 1), f = 0;
}
string process(int x) {
  string s = val[x];
  if (pro.count(s)) return pro[s];
  string l, r, o;
  bool f = 1;
  split(s, l, r, o, f);
  if (f) {
    if (to_string(x) == s) {
      r = pro[s] = back[x];
      if (x == rval) res.emplace_back("res=" + r);
      return r;
    }
    if (x == rval) rval = stoi(s);
    return pro[s] = process(stoi(s));
  }
  string proc = process(stoi(l)) + o + process(stoi(r));
  bool done = pro.count(proc);
  r = done ? pro[proc] : pro[proc] = "a" + to_string(nxt++);
  if (!done) res.emplace_back((x == rval ? "res" : r) + "=" + proc);
  return pro[s] = r;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  string t[n];
  for (int i = int(0); i < int(n); i++) cin >> t[i];
  for (int i = int(0); i < int(n); i++) {
    int x = int(t[i].find('=')), ne, nl, nr;
    string var = t[i].substr(0, x), exp = t[i].substr(x + 1), l, r, o;
    bool f = 1;
    split(exp, l, r, o, f);
    if (f) {
      if (!num.count(exp))
        ne = num[exp] = nxt++, val[ne] = to_string(ne), back[ne] = exp;
      val[num[var] = nxt++] = to_string(num[exp]);
    } else {
      if (!num.count(l))
        nl = num[l] = nxt++, val[nl] = to_string(nl), back[nl] = l;
      if (!num.count(r))
        nr = num[r] = nxt++, val[nr] = to_string(nr), back[nr] = r;
      val[num[var] = nxt++] = to_string(num[l]) + o + to_string(num[r]);
    }
  }
  if (!num.count("res")) return cout << "0\n", 0;
  nxt = 0, rval = num["res"], process(rval);
  int sz = int((res).size());
  if (sz == 1 && res[0] == "res=res") return cout << "0\n", 0;
  cout << sz << '\n';
  for (int j = int(0); j < int(sz); j++) cout << res[j] << '\n';
  return 0;
}