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;
long long getp(string s) {
  for (long long i = 0; i < (long long)s.size(); ++i) {
    if (s[i] == '$' || s[i] == '^' || s[i] == '#' || s[i] == '&') {
      return i;
    }
  }
  return -1;
}
const long long N = 1e5 + 7;
vector<long long> g[N];
char op_[N];
map<string, long long> last;
bool used[N];
string mem[N];
set<string> us;
string my_name[N];
long long par[N];
mt19937 rnd(228);
string name(long long u) {
  if (my_name[u].empty()) {
    if (g[u].empty()) {
      my_name[u] = mem[u];
    } else {
      while (1) {
        string nn;
        for (long long i = 0; i < 4; ++i) {
          nn += (rnd() % 26) + 'a';
        }
        if (us.find(nn) == us.end()) {
          us.insert(nn);
          my_name[u] = nn;
          break;
        }
      }
    }
  }
  return my_name[u];
}
vector<string> ans;
void jfs(long long u, bool c) {
  if (g[u].empty() || used[u]) return;
  used[u] = 1;
  for (long long v : g[u]) jfs(v, 0);
  if (c) {
    ans.push_back("res=" + name(g[u][0]) + op_[u] + name(g[u][1]));
  } else {
    ans.push_back(name(u) + '=' + name(g[u][0]) + op_[u] + name(g[u][1]));
  }
  us.insert(name(u));
  us.insert(name(g[u][0]));
  us.insert(name(g[u][1]));
}
long long ptr = 0;
void check(string s) {
  if (last.find(s) == last.end()) {
    mem[ptr] = s;
    last[s] = ptr++;
  }
}
pair<string, string> split(string s) {
  long long p = -1;
  for (long long j = 0; j < (long long)s.size(); ++j) {
    if (s[j] == '=') {
      p = j;
      break;
    }
  }
  return {s.substr(0, p), s.substr(p + 1, (long long)s.size() - p - 1)};
}
vector<string> form(vector<string> a) {
  vector<string> ans;
  for (auto e : a) {
    auto t = split(e);
    if (t.first != t.second) {
      ans.push_back(e);
    }
  }
  return ans;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n;
  cin >> n;
  for (long long i = 0; i < n; ++i) {
    string s;
    cin >> s;
    auto t = split(s);
    string l = t.first, r = t.second;
    long long p = getp(r);
    if (p != -1) {
      string op_l = r.substr(0, p);
      char op = r[p];
      string op_r = r.substr(p + 1, (long long)r.size() - p - 1);
      check(op_l);
      check(op_r);
      g[ptr] = {last[op_l], last[op_r]};
      mem[ptr] = l;
      op_[ptr] = op;
      last[l] = ptr;
      ++ptr;
    } else {
      if (l != r) {
        check(r);
        last[l] = last[r];
      }
    }
  }
  for (long long i = 0; i < ptr; ++i) {
    for (auto &e : g[i]) e = par[e];
    par[i] = i;
    for (long long j = 0; j < i; ++j) {
      if (par[j] == j && op_[i] == op_[j] && g[i].size() && g[i] == g[j]) {
        par[i] = j;
        break;
      }
    }
  }
  if (last.find("res") == last.end()) {
    cout << "0\n";
  } else if (g[last["res"]].empty()) {
    jfs(last["res"], 0);
    ans.push_back("res=" + name(last["res"]));
    ans = form(ans);
    cout << ans.size() << '\n';
    for (auto e : ans) cout << e << '\n';
  } else {
    jfs(last["res"], 1);
    ans = form(ans);
    cout << ans.size() << '\n';
    for (auto e : ans) cout << e << '\n';
  }
}