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;
map<string, int> strs;
map<tuple<int, int, char>, int> adj;
vector<string> roots;
vector<tuple<int, int, char> > radj;
int getNode(string const& s) {
  auto it = strs.find(s);
  if (it != end(strs)) return it->second;
  int c = ((int)(roots).size());
  strs[s] = c;
  roots.push_back(s);
  return c;
}
string getname(int i) {
  char a[100];
  int x = i / 1000, y = i % 1000;
  sprintf(a, "%c%03d", 'a' + x, y);
  return a;
}
int V;
vector<string> ans;
vector<int> cache;
string dfs(int n, bool root) {
  if (cache[n] != -1) return getname(cache[n]);
  string rn = roots[n];
  if (!rn.empty()) return rn;
  tuple<int, int, char> const& e = radj[n];
  string c0 = dfs(get<0>(e), false);
  string c1 = dfs(get<1>(e), false);
  string myname = "res";
  if (!root) {
    int vn = V++;
    myname = getname(vn);
    cache[n] = vn;
  }
  string s = myname + "=" + c0 + get<2>(e) + c1;
  ans.push_back(move(s));
  return myname;
}
int main() {
  ios_base::sync_with_stdio(false);
  int N;
  cin >> N;
  string tmp, va, vb, vc;
  for (int n = 0; n < int(N); n++) {
    cin >> tmp;
    int p0 = (int)tmp.find('=');
    va = tmp.substr(0, p0);
    int p1 = p0 + 1;
    while (p1 < ((int)(tmp).size()) && !(tmp[p1] == '$' || tmp[p1] == '^' ||
                                         tmp[p1] == '#' || tmp[p1] == '&'))
      ++p1;
    char op = 0;
    if (p1 == ((int)(tmp).size())) {
      vb = tmp.substr(p0 + 1);
      vc = "";
      if (va != vb) {
        int c = getNode(vb);
        strs[va] = c;
      }
    } else {
      op = tmp[p1];
      vb = tmp.substr(p0 + 1, p1 - p0 - 1);
      vc = tmp.substr(p1 + 1);
      int cb = getNode(vb), cc = getNode(vc);
      tuple<int, int, char> ed(cb, cc, op);
      int c;
      auto it = adj.find(ed);
      if (it != end(adj)) {
        c = it->second;
      } else {
        c = ((int)(roots).size());
        adj[ed] = c;
        roots.push_back("");
      }
      strs[va] = c;
    }
  }
  radj.resize(roots.size());
  cache.assign(roots.size(), -1);
  for (auto const& it : adj) radj[it.second] = it.first;
  auto ri = strs.find("res");
  if (ri != end(strs)) {
    string a = dfs(ri->second, true);
    if (a != "res") ans.push_back("res=" + a);
  }
  cout << ans.size() << '\n';
  for (string const& s : ans) cout << s << '\n';
}