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 int INF = 1e9 + 7;
map<string, int> m;
string mmm[3003], mmmmm[3003];
map<pair<pair<int, int>, char>, int> mm;
int mmmm;
vector<string> ans;
string tos(int m) {
  string ret;
  for (int i = 0; i < 4; i++) ret += char('a' + m % 26), m /= 26;
  return ret;
}
string getname() {
  static int mmmmmm = 0;
  while (m.count(tos(mmmmmm))) mmmmmm++;
  return tos(mmmmmm++);
}
void M(int x) {
  if (mmmmm[x].size()) return;
  string s = mmm[x];
  if (isdigit(s[0])) {
    stringstream ss(s);
    int a, b;
    char op;
    ss >> a >> op >> b;
    M(a);
    M(b);
    if (x == m["res"])
      mmmmm[x] = "res";
    else
      mmmmm[x] = getname();
    ans.push_back(mmmmm[x] + '=' + mmmmm[a] + op + mmmmm[b]);
  } else {
    mmmmm[x] = s;
  }
}
int main() {
  std::ios::sync_with_stdio(0);
  std::cin.tie(0);
  ;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    string a = s.substr(0, s.find("="));
    string b = s.substr(s.find("=") + 1);
    char op = 0;
    string ops = "$^#&";
    for (char c : ops)
      if (b.find(c) != string::npos) op = c;
    if (op) {
      string x = b.substr(0, b.find(op));
      string y = b.substr(b.find(op) + 1);
      if (!m.count(x)) {
        mmm[mmmm] = x;
        m[x] = mmmm++;
      }
      if (!m.count(y)) {
        mmm[mmmm] = y;
        m[y] = mmmm++;
      }
      pair<pair<int, int>, char> exp(pair<int, int>(m[x], m[y]), op);
      if (!mm.count(exp)) {
        mmm[mmmm] = to_string(m[x]) + op + to_string(m[y]);
        mm[exp] = mmmm++;
      }
      m[a] = mm[exp];
    } else {
      if (a == b) continue;
      if (!m.count(b)) {
        mmm[mmmm] = b;
        m[b] = mmmm++;
      }
      m[a] = m[b];
    }
  }
  if (!m.count("res")) {
    cout << 0 << endl;
    return 0;
  }
  M(m["res"]);
  if (ans.size() == 0) {
    if (mmmmm[m["res"]] == "res")
      cout << "0\n";
    else
      cout << "1\nres=" << mmmmm[m["res"]] << endl;
    return 0;
  }
  cout << ans.size() << endl;
  for (string s : ans) cout << s << endl;
}