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;
int N;
set<string> S;
string L[1010], R1[1010], R2[1010], O[1010];
map<string, string> name;
string lastres;
map<string, vector<string>> M;
map<string, int> line;
map<string, string> cache;
string nex(string s) {
  int i = s.size() - 1;
  while (1) {
    s[i]++;
    if (s[i] == 'z' + 1) {
      s[i] = 'a';
      i--;
    } else
      break;
  }
  return s;
}
string tag() {
  static string s = "aaaa";
  s = nex(s);
  while (S.count(s)) s = nex(s);
  return s;
}
void solve() {
  int i, j, k, l, r, x, y;
  string s;
  cin >> N;
  for (i = 0; i < (N); i++) {
    cin >> s;
    x = s.find('=');
    L[i] = s.substr(0, x);
    s = s.substr(x + 1);
    x = s.find_first_of("$^#&");
    if (x != string::npos) {
      R1[i] = s.substr(0, x);
      O[i] = s.substr(x, 1);
      R2[i] = s.substr(x + 1);
      if (name.count(R1[i]) == 0) name[R1[i]] = R1[i];
      if (name.count(R2[i]) == 0) name[R2[i]] = R2[i];
      R1[i] = name[R1[i]];
      R2[i] = name[R2[i]];
      name[L[i]] = tag();
      string tmp = R1[i] + O[i] + R2[i];
      if (cache.count(tmp)) {
        name[L[i]] = cache[tmp];
        if (L[i] == "res") lastres = name[L[i]];
        L[i] = "";
      } else {
        cache[tmp] = name[L[i]];
      }
    } else {
      R1[i] = s;
      if (L[i] == R1[i]) {
        L[i] == "";
        continue;
      }
      if (name.count(R1[i]) == 0) name[R1[i]] = R1[i];
      R1[i] = name[R1[i]];
      name[L[i]] = R1[i];
    }
    if (L[i] == "res") lastres = name[L[i]];
    L[i] = name[L[i]];
  }
  if (lastres == "") return (void)printf("0\n");
  set<string> T;
  T.insert(lastres);
  vector<string> ret;
  for (i = N - 1; i >= 0; i--) {
    if (L[i].size() && T.count(L[i])) {
      if (O[i].size()) {
        if (L[i] == lastres) {
          L[i] = "res";
        }
        ret.push_back(L[i] + "=" + R1[i] + O[i] + R2[i]);
        T.insert(R1[i]);
        T.insert(R2[i]);
      }
    }
  }
  if (ret.empty() && lastres != "res") ret.push_back("res=" + lastres);
  cout << ret.size() << endl;
  reverse((ret.begin()), (ret.end()));
  for (auto& r : ret) cout << r << endl;
}
int main(int argc, char** argv) {
  string s;
  int i;
  if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);
  for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s += '\n';
  for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);
  cout.tie(0);
  solve();
  return 0;
}