#include <bits/stdc++.h>
using namespace std;
inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; }
inline bool setmin(long long &x, long long y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(long long &x, long long y) { return (y > x) ? x = y, 1 : 0; }
const int N = 200000;
const int inf = (int)1e9 + 1;
const long long big = (long long)1e18 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const int MOD2 = 998244353;
const double eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;
struct var {
  int a1, a2;
  char op;
  var(int a1, int a2, char op) : a1(a1), a2(a2), op(op) {}
};
vector<var> V;
map<string, int> mapa;
set<string> used;
map<int, string> init;
map<pair<pair<int, int>, char>, int> MAPA;
map<int, string> toSTR;
string f(int x) {
  string res;
  for (int i = 0; i < 4; i++) {
    res += char('a' + x % 26);
    x /= 26;
  }
  reverse(res.begin(), res.end());
  return res;
}
string getStr(int x) {
  int xxx = x;
  if (x == mapa["res"]) {
    return "res";
  }
  if (init.count(x)) {
    return init[x];
  }
  if (toSTR.count(x)) {
    return toSTR[x];
  }
  while (used.count(f(x))) {
    x++;
  }
  used.insert(f(x));
  return toSTR[xxx] = f(x);
}
vector<string> out;
set<int> was;
void restore(int id) {
  if (V[id].op == '.') {
    return;
  }
  if (!was.count(V[id].a1)) {
    restore(V[id].a1);
  }
  if (!was.count(V[id].a2)) {
    restore(V[id].a2);
  }
  out.push_back(getStr(id) + "=" + getStr(V[id].a1) + V[id].op +
                getStr(V[id].a2));
  was.insert(id);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.precision(20);
  cout << fixed;
  int n;
  cin >> n;
  int curID = 0;
  int ANS_ID = -1;
  string ANS_STR = "";
  for (int t = 0; t < n; t++) {
    string s;
    cin >> s;
    int p1 = -1, p2 = -1;
    for (int i = 0; i < (int)s.size(); i++) {
      if (s[i] == '=') {
        p1 = i;
      }
      if (s[i] == '$' || s[i] == '^' || s[i] == '#' || s[i] == '&') {
        p2 = i;
      }
    }
    if (p2 == -1) {
      string a = s.substr(0, p1), b = s.substr(p1 + 1, (int)s.size() - p1 - 1);
      if (a == b) {
        continue;
      }
      if (mapa.find(b) == mapa.end()) {
        mapa[b] = curID++;
        init[mapa[b]] = b;
        used.insert(b);
        V.push_back(var(-1, -1, '.'));
      }
      if (a == "res") {
        if (V[mapa[b]].op == '.') {
          ANS_ID = mapa[b];
          ANS_STR = init[mapa[b]];
        }
      }
      mapa[a] = mapa[b];
    } else {
      string a = s.substr(0, p1), b = s.substr(p1 + 1, p2 - p1 - 1),
             c = s.substr(p2 + 1, (int)s.size() - p2 - 1);
      if (mapa.find(b) == mapa.end()) {
        mapa[b] = curID++;
        init[mapa[b]] = b;
        used.insert(b);
        V.push_back(var(-1, -1, '.'));
      }
      if (mapa.find(c) == mapa.end()) {
        mapa[c] = curID++;
        init[mapa[c]] = c;
        used.insert(c);
        V.push_back(var(-1, -1, '.'));
      }
      int idB = mapa[b], idC = mapa[c];
      auto it = MAPA.find({{idB, idC}, s[p2]});
      if (it == MAPA.end()) {
        V.push_back(var(idB, idC, s[p2]));
        mapa[a] = curID++;
        MAPA[{{idB, idC}, s[p2]}] = mapa[a];
      } else {
        mapa[a] = it->second;
      }
    }
  }
  if (mapa.find("res") == mapa.end()) {
    cout << 0 << "\n";
    return 0;
  }
  if (mapa["res"] == ANS_ID) {
    if (ANS_STR == "res") {
      cout << 0 << "\n";
      return 0;
    }
    cout << 1 << "\n";
    cout << "res=" << ANS_STR << "\n";
    return 0;
  }
  restore(mapa["res"]);
  cout << (int)out.size() << "\n";
  for (auto it : out) {
    cout << it << "\n";
  }
  return 0;
}

### Prompt

Your challenge is to write a CPP solution to the following 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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; }
inline bool setmin(long long &x, long long y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(long long &x, long long y) { return (y > x) ? x = y, 1 : 0; }
const int N = 200000;
const int inf = (int)1e9 + 1;
const long long big = (long long)1e18 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const int MOD2 = 998244353;
const double eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;
struct var {
  int a1, a2;
  char op;
  var(int a1, int a2, char op) : a1(a1), a2(a2), op(op) {}
};
vector<var> V;
map<string, int> mapa;
set<string> used;
map<int, string> init;
map<pair<pair<int, int>, char>, int> MAPA;
map<int, string> toSTR;
string f(int x) {
  string res;
  for (int i = 0; i < 4; i++) {
    res += char('a' + x % 26);
    x /= 26;
  }
  reverse(res.begin(), res.end());
  return res;
}
string getStr(int x) {
  int xxx = x;
  if (x == mapa["res"]) {
    return "res";
  }
  if (init.count(x)) {
    return init[x];
  }
  if (toSTR.count(x)) {
    return toSTR[x];
  }
  while (used.count(f(x))) {
    x++;
  }
  used.insert(f(x));
  return toSTR[xxx] = f(x);
}
vector<string> out;
set<int> was;
void restore(int id) {
  if (V[id].op == '.') {
    return;
  }
  if (!was.count(V[id].a1)) {
    restore(V[id].a1);
  }
  if (!was.count(V[id].a2)) {
    restore(V[id].a2);
  }
  out.push_back(getStr(id) + "=" + getStr(V[id].a1) + V[id].op +
                getStr(V[id].a2));
  was.insert(id);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.precision(20);
  cout << fixed;
  int n;
  cin >> n;
  int curID = 0;
  int ANS_ID = -1;
  string ANS_STR = "";
  for (int t = 0; t < n; t++) {
    string s;
    cin >> s;
    int p1 = -1, p2 = -1;
    for (int i = 0; i < (int)s.size(); i++) {
      if (s[i] == '=') {
        p1 = i;
      }
      if (s[i] == '$' || s[i] == '^' || s[i] == '#' || s[i] == '&') {
        p2 = i;
      }
    }
    if (p2 == -1) {
      string a = s.substr(0, p1), b = s.substr(p1 + 1, (int)s.size() - p1 - 1);
      if (a == b) {
        continue;
      }
      if (mapa.find(b) == mapa.end()) {
        mapa[b] = curID++;
        init[mapa[b]] = b;
        used.insert(b);
        V.push_back(var(-1, -1, '.'));
      }
      if (a == "res") {
        if (V[mapa[b]].op == '.') {
          ANS_ID = mapa[b];
          ANS_STR = init[mapa[b]];
        }
      }
      mapa[a] = mapa[b];
    } else {
      string a = s.substr(0, p1), b = s.substr(p1 + 1, p2 - p1 - 1),
             c = s.substr(p2 + 1, (int)s.size() - p2 - 1);
      if (mapa.find(b) == mapa.end()) {
        mapa[b] = curID++;
        init[mapa[b]] = b;
        used.insert(b);
        V.push_back(var(-1, -1, '.'));
      }
      if (mapa.find(c) == mapa.end()) {
        mapa[c] = curID++;
        init[mapa[c]] = c;
        used.insert(c);
        V.push_back(var(-1, -1, '.'));
      }
      int idB = mapa[b], idC = mapa[c];
      auto it = MAPA.find({{idB, idC}, s[p2]});
      if (it == MAPA.end()) {
        V.push_back(var(idB, idC, s[p2]));
        mapa[a] = curID++;
        MAPA[{{idB, idC}, s[p2]}] = mapa[a];
      } else {
        mapa[a] = it->second;
      }
    }
  }
  if (mapa.find("res") == mapa.end()) {
    cout << 0 << "\n";
    return 0;
  }
  if (mapa["res"] == ANS_ID) {
    if (ANS_STR == "res") {
      cout << 0 << "\n";
      return 0;
    }
    cout << 1 << "\n";
    cout << "res=" << ANS_STR << "\n";
    return 0;
  }
  restore(mapa["res"]);
  cout << (int)out.size() << "\n";
  for (auto it : out) {
    cout << it << "\n";
  }
  return 0;
}

```