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;
unordered_map<string, int> value;
int vcnt = 0;
unordered_map<int, string> start_value;
int getv(string s) {
  if (value.find(s) == value.end()) {
    value[s] = ++vcnt;
    start_value[vcnt] = s;
  }
  return value[s];
}
map<tuple<int, int, int>, int> equation;
tuple<int, int, int> evalue[10010];
vector<string> ans;
int op[10010][2];
int n;
unordered_set<string> used_name;
unordered_map<int, string> new_value;
const string options = "$^#&";
mt19937 rnd(time(0));
int getopt(char c) {
  for (int i = 0; i < 4; i++)
    if (options[i] == c) return i;
  return 4;
}
string getname() {
  string str = "aaaa";
  while (used_name.count(str)) {
    str[rnd() % 4] = rnd() % 26 + 'a';
  }
  used_name.insert(str);
  return str;
}
void dfs(int np, bool is_des) {
  if (start_value.count(np)) {
    if (is_des && start_value[np] != "res") {
      ans.push_back("res=" + start_value[np]);
    }
    new_value[np] = start_value[np];
    return;
  }
  if (new_value.count(np)) return;
  auto v = evalue[np];
  dfs(get<0>(v), 0);
  dfs(get<1>(v), 0);
  ans.push_back((new_value[np] = (is_des ? "res" : getname())) + "=" +
                new_value[get<0>(v)] + string({options[get<2>(v)]}) +
                new_value[get<1>(v)]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    string str;
    cin >> str;
    auto p = str.find('=');
    auto ip = p;
    string des = str.substr(0, p);
    getv(des);
    while (p < str.size() && getopt(str[p]) == 4) p++;
    if (p == str.size()) {
      string b = str.substr(ip + 1);
      value[des] = getv(b);
    } else {
      string b = str.substr(ip + 1, p - ip - 1);
      string c = str.substr(p + 1);
      getv(b);
      getv(c);
      auto cur = make_tuple(value[b], value[c], getopt(str[p]));
      if (!equation.count(cur)) equation[cur] = ++vcnt, evalue[vcnt] = cur;
      value[des] = equation[cur];
    }
  }
  if (!value.count("res")) {
    puts("0");
    return 0;
  }
  dfs(value["res"], 1);
  cout << ans.size() << '\n';
  for (auto &x : ans) cout << x << '\n';
  return 0;
}