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 long long MAXN = 1009;
string a[MAXN][4];
long long n;
bool u[MAXN];
string name[10 * MAXN];
long long pt;
string gen(map<string, vector<pair<long long, long long> > >& pos) {
  while (pos.find(name[pt]) != pos.end()) {
    pt++;
    if (pt >= 10 * MAXN) pt = 0;
  }
  return name[pt];
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  for (char e0 = 'a'; e0 <= 'z'; e0++) {
    for (char e1 = 'a'; e1 <= 'z'; e1++) {
      for (char e2 = 'a'; e2 <= 'z'; e2++) {
        string u0 = "";
        u0 += e0;
        string u1 = "";
        u1 += e1;
        string u2 = "";
        u2 += e2;
        string cur = u0 + u1 + u2;
        name[pt] = cur;
        pt++;
        if (pt >= 10 * MAXN) break;
      }
      if (pt >= 10 * MAXN) break;
    }
    if (pt >= 10 * MAXN) break;
  }
  pt = 0;
  cin >> n;
  set<char> xx;
  xx.insert('$');
  xx.insert('^');
  xx.insert('#');
  xx.insert('&');
  for (long long i = 0; i < n; i++) {
    string s;
    cin >> s;
    long long e = 0;
    while (s[e] != '=') {
      a[i][0] += s[e];
      e++;
    }
    e++;
    while (e < (long long)s.size() && (xx.find(s[e]) == xx.end())) {
      a[i][1] += s[e];
      e++;
    }
    if (e != (long long)s.size()) {
      a[i][2] += s[e];
      e++;
    }
    while (e < (long long)s.size()) {
      a[i][3] += s[e];
      e++;
    }
  }
  for (long long i = 0; i < n; i++) {
    if (a[i][2].empty() && a[i][0] == a[i][1]) {
      for (long long e = i; e < n - 1; e++) {
        for (long long j = 0; j < 4; j++) a[e][j] = a[e + 1][j];
      }
      n--;
      i--;
    }
  }
  while (n > 0 && a[n - 1][0] != "res") n--;
  if (n == 0) {
    cout << 0;
    return 0;
  }
  map<string, vector<pair<long long, long long> > > pos;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < 4; j++) {
      if (!a[i][j].empty() && j != 2) pos[a[i][j]].emplace_back(i, j);
    }
  }
  set<string> used;
  for (long long i = 0; i < n - 1; i++) {
    used.insert(a[i][1]);
    if (!a[i][3].empty()) used.insert(a[i][3]);
    if (used.find(a[i][0]) != used.end() || a[i][0] == "res") {
      string x = gen(pos);
      auto j = pos.find(a[i][0]);
      long long m = (*j).second.size();
      for (long long e = 0; e < m; e++) {
        pair<long long, long long> cur = ((*j).second)[e];
        if ((cur.first > i || (cur.first == i && cur.second == 0)) &&
            !(cur.first == n - 1 && cur.second == 0)) {
          pos[x].emplace_back(cur);
          a[cur.first][cur.second] = x;
          (*j).second.erase((*j).second.begin() + e);
          e--;
          m--;
        }
      }
    }
    used.insert(a[i][0]);
  }
  used.clear();
  for (long long i = 0; i < n; i++) u[i] = true;
  for (long long i = 0; i < n - 1; i++) {
    if (!u[i]) continue;
    if (a[i][2].empty() && a[i][0] == a[i][1])
      u[i] = false;
    else if (a[i][2].empty()) {
      string x1 = a[i][0];
      string x2 = a[i][1];
      auto j = pos.find(x1);
      long long m = (*j).second.size();
      for (long long e = 0; e < m; e++) {
        pair<long long, long long> cur = ((*j).second)[e];
        if (cur.first > i && u[cur.first]) {
          pos[x2].emplace_back(cur);
          a[cur.first][cur.second] = x2;
          (*j).second.erase((*j).second.begin() + e);
          e--;
          m--;
        }
      }
      u[i] = false;
    }
  }
  for (long long i = 0; i < n - 1; i++) {
    if (!u[i]) continue;
    for (long long e = 0; e < i; e++) {
      if (!u[e]) continue;
      if (a[i][1] == a[e][1] && a[i][2] == a[e][2] && a[i][3] == a[e][3]) {
        string x1 = a[i][0];
        string x2 = a[e][0];
        auto j = pos.find(x1);
        long long m = (*j).second.size();
        for (long long e = 0; e < m; e++) {
          pair<long long, long long> cur = ((*j).second)[e];
          if (cur.first > i && u[cur.first]) {
            pos[x2].emplace_back(cur);
            a[cur.first][cur.second] = x2;
            (*j).second.erase((*j).second.begin() + e);
            e--;
            m--;
          }
        }
        u[i] = false;
        break;
      }
    }
  }
  if (a[n - 1][2].empty()) {
    string x = a[n - 1][1];
    auto j = pos.find(x);
    long long m = (*j).second.size();
    for (long long e = 0; e < m; e++) {
      pair<long long, long long> cur = ((*j).second)[e];
      if (cur.second == 0 && u[cur.first]) {
        a[n - 1][1] = a[cur.first][1];
        a[n - 1][2] = a[cur.first][2];
        a[n - 1][3] = a[cur.first][3];
      }
    }
  }
  if (a[n - 1][2].empty() && a[n - 1][1] == "res") {
    cout << 0;
    return 0;
  }
  used.insert(a[n - 1][1]);
  used.insert(a[n - 1][3]);
  long long cnt = 1;
  for (long long e = n - 2; e >= 0; e--) {
    if (!u[e]) continue;
    if (used.find(a[e][0]) == used.end())
      u[e] = false;
    else {
      cnt++;
      used.insert(a[e][1]);
      used.insert(a[e][3]);
    }
  }
  cout << cnt << "\n";
  for (long long i = 0; i < n; i++) {
    if (u[i]) cout << a[i][0] << "=" << a[i][1] << a[i][2] << a[i][3] << "\n";
  }
}