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;
#pragma warning(disable : 4996)
const int N = 2e6, D = 36;
map<char, int> mp = {{'=', -1}, {'$', 0}, {'#', 1}, {'&', 2}, {'^', 3}};
string ops = "$#&^";
int z = 0;
bool used[N], need[N];
int w[N];
pair<int, int> ar[N];
map<pair<int, int>, int> mp2[4];
int toI(char c) {
  if (isalpha(c)) return c - 'a';
  return c - '0' + 26;
}
char toC(int i) {
  if (i < 26) return i + 'a';
  return i - 26 + '0';
}
int getId(string s) {
  int x = 0, y = 26;
  for (char c : s) {
    x = x * D + toI(c);
  }
  for (int i = 0; i < s.size() - 1; i++) {
    x += y;
    y *= D;
  }
  return x;
}
int getNext() {
  while (used[z]) z++;
  used[z] = 1;
  return z;
}
string getString(int x) {
  int y = 26, len = 1;
  while (x >= y) {
    x -= y;
    y *= D;
    len++;
  }
  string s;
  for (int i = 0; i < len; i++) {
    s.push_back(toC(x % D));
    x /= D;
  }
  reverse(s.begin(), s.end());
  return s;
}
void dfs(int node) {
  if (need[node]) return;
  need[node] = 1;
  if (ar[node].first != -1) {
    dfs(ar[node].first);
    dfs(ar[node].second);
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<vector<int>> v;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int j = 0;
    while (!mp.count(s[j])) j++;
    v.push_back({});
    v.back().push_back(getId(s.substr(0, j)));
    j++;
    int k = j;
    while (j < s.size() && !mp.count(s[j])) j++;
    v.back().push_back(getId(s.substr(k, j - k)));
    if (j != s.size()) {
      v.back().push_back(mp[s[j]]);
      v.back().push_back(getId(s.substr(j + 1, s.size() - j - 1)));
    }
  }
  for (auto& t : v) {
    used[t[0]] = 1;
    used[t[1]] = 1;
    if (t.size() > 2) used[t[3]] = 1;
  }
  for (int i = 0; i < N; i++) {
    w[i] = i;
    ar[i] = {-1, -1};
  }
  used[getId("res")] = 1;
  vector<vector<int>> ans;
  for (int i = 0; i < v.size(); i++) {
    auto& t = v[i];
    if (t.size() == 2) {
      w[t[0]] = w[t[1]];
    } else {
      if (!mp2[t[2]].count({w[t[1]], w[t[3]]})) {
        int m = getNext();
        mp2[t[2]][{w[t[1]], w[t[3]]}] = m;
        ar[m] = {w[t[1]], w[t[3]]};
        ans.push_back({m, w[t[1]], t[2], w[t[3]]});
      }
      w[t[0]] = mp2[t[2]][{w[t[1]], w[t[3]]}];
    }
  }
  int resId = getId("res");
  dfs(w[resId]);
  int k = 0;
  for (auto& v : ans) {
    if (need[v[0]]) {
      k++;
    }
  }
  if (k == 0 && w[resId] != resId) {
    cout << "1\nres=" << getString(w[resId]);
    return 0;
  }
  cout << k << "\n";
  for (auto& v : ans) {
    if (need[v[0]]) {
      if (v[0] == w[resId])
        cout << "res";
      else
        cout << getString(v[0]);
      cout << "=" << getString(v[1]) << ops.substr(v[2], 1) << getString(v[3])
           << "\n";
    }
  }
  return 0;
}