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, string> newname;
vector<vector<string> > lines;
map<string, long long> lineno;
set<string> allnames, nontempnames;
long long idx = 0;
vector<long long> marklines;
long long ctr = 0;
string allpermit = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
string nexttemp() {
  string s = "AAAA";
  do {
    for (long long i = 0; i < 4; i++)
      s[i] = allpermit[rand() % allpermit.size()];
    if (allnames.count(s)) continue;
    allnames.insert(s);
    return s;
  } while (1);
}
vector<string> proc(const string &s) {
  string lvalue, rvalue1, rvalue2, op;
  long long n = s.size();
  string ops = "$^#&";
  long long i;
  for (i = 0; i < n; i++) {
    if (s[i] == '=') break;
    lvalue.push_back(s[i]);
  }
  allnames.insert(lvalue);
  nontempnames.insert(lvalue);
  i++;
  for (; i < n; i++) {
    if (ops.find(s[i]) != string::npos) {
      op = s[i];
      break;
    }
    rvalue1.push_back(s[i]);
  }
  allnames.insert(rvalue1);
  nontempnames.insert(rvalue1);
  i++;
  for (; i < n; i++) {
    rvalue2.push_back(s[i]);
  }
  if (rvalue2.size()) {
    allnames.insert(rvalue2);
    nontempnames.insert(rvalue2);
  }
  if (op.empty()) return {lvalue, rvalue1};
  return {lvalue, rvalue1, op, rvalue2};
}
void proc2() {
  for (auto &i : lines) {
    string nval;
    auto it = newname.find(i[1]);
    if (it != newname.end()) {
      i[1] = it->second;
    }
    if (i.size() > 2) {
      it = newname.find(i[3]);
      if (it != newname.end()) {
        i[3] = it->second;
      }
    }
    nval = nexttemp();
    newname[i[0]] = nval;
    newname[nval] = nval;
    lineno[nval] = idx++;
    i[0] = nval;
  }
}
long long getlineno(const string &s) {
  auto it = lineno.find(s);
  if (it != lineno.end()) return it->second;
  return -1;
}
void dfs(long long loc) {
  if (loc == -1) return;
  if (marklines[loc] == 2) return;
  marklines[loc] = 2;
  dfs(getlineno(lines[loc][1]));
  if (lines[loc].size() == 4) dfs(getlineno(lines[loc][3]));
}
string get(const map<string, string> &m, const string &s) {
  auto it = m.find(s);
  if (it != m.end()) {
    return it->second;
  } else
    return s;
}
int32_t main() {
  srand(time(0));
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  marklines.resize(n);
  string s;
  for (long long i = 0; i < n; i++) {
    cin >> s;
    if (s == "res=res") {
      i--;
      n--;
      continue;
    }
    lines.push_back(proc(s));
  }
  proc2();
  stringstream ss;
  long long totlines = 0;
  auto it = lineno.find(newname["res"]);
  if (it != lineno.end()) {
    long long blem = it->second;
    long long tmp = getlineno(lines[blem][1]);
    while (lines[blem].size() == 2 && tmp != -1) {
      blem = tmp;
      tmp = getlineno(lines[blem][1]);
    }
    dfs(blem);
    newname.clear();
    for (long long i = 0; i < lines.size(); i++) {
      if (marklines[i] == 2) {
        if (lines[i].size() == 2) {
          newname[lines[i][0]] = get(newname, lines[i][1]);
          if (i == blem && newname[lines[i][0]] != "res") {
            totlines++;
            ss << "res=" << newname[lines[i][0]] << endl;
          }
        } else {
          string tocheck = get(newname, lines[i][1]) + lines[i][2] +
                           get(newname, lines[i][3]);
          auto it = newname.find(tocheck);
          if (it != newname.end()) {
            newname[lines[i][0]] = get(newname, it->second);
          } else {
            newname[tocheck] = get(newname, lines[i][0]);
            totlines++;
            if (i == blem)
              ss << "res";
            else
              ss << get(newname, lines[i][0]);
            ss << "=" << get(newname, lines[i][1]) << lines[i][2]
               << get(newname, lines[i][3]) << endl;
          }
        }
      }
    }
    cout << totlines << endl << ss.str();
  } else {
    cout << 0;
  }
  return 0;
}