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;
vector<tuple<int, char, int> > nodes;
vector<string> names;
unordered_map<string, int> vars;
unordered_set<int> used;
string next_token(const char *&str) {
  string ret;
  for (; (*str >= '0' && *str <= '9') || (*str >= 'a' && *str <= 'z') ||
         (*str >= 'A' && *str <= 'Z');
       str++) {
    ret += *str;
  }
  return ret;
}
string getname(int x) {
  std::ostringstream out;
  if (get<1>(nodes[x]) != '\0') {
    out << 't' << std::hex << x;
  } else {
    out << names[x];
  }
  return out.str();
}
void dfs(int x, vector<string> &outputs) {
  if (used.count(x)) {
    return;
  }
  std::ostringstream out;
  tuple<int, char, int> &n = nodes[x];
  string lname = getname(x);
  if (vars.count("res") && vars["res"] == x) {
    lname = "res";
  }
  string arg1name = getname(get<0>(n));
  if (get<1>(nodes[get<0>(n)]) != '\0') {
    dfs(get<0>(n), outputs);
  }
  string arg2name = getname(get<2>(n));
  if (get<1>(nodes[get<2>(n)]) != '\0') {
    dfs(get<2>(n), outputs);
  }
  out << lname << '=' << arg1name << get<1>(n) << arg2name;
  outputs.push_back(out.str());
  used.insert(x);
}
int main() {
  names.push_back("res");
  nodes.push_back(tuple<int, char, int>(0, '\0', 0));
  vars["res"] = 0;
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    string line;
    cin >> line;
    const char *str = line.c_str();
    string lvalue = next_token(str);
    size_t lvalue_node = names.size();
    names.push_back(lvalue);
    nodes.push_back(tuple<int, char, int>(0, '\0', 0));
    str++;
    string arg1 = next_token(str);
    size_t arg1_node = names.size();
    if (vars.count(arg1) == 0) {
      vars[arg1] = names.size();
      names.push_back(arg1);
      nodes.push_back(tuple<int, char, int>(0, '\0', 0));
    } else {
      arg1_node = vars[arg1];
    }
    if (*str == '\0') {
      vars[lvalue] = arg1_node;
      continue;
    }
    char op = *str;
    str++;
    string arg2 = next_token(str);
    size_t arg2_node = names.size();
    if (vars.count(arg2) == 0) {
      vars[arg2] = names.size();
      names.push_back(arg2);
      nodes.push_back(tuple<int, char, int>(0, '\0', 0));
    } else {
      arg2_node = vars[arg2];
    }
    nodes[lvalue_node] = tuple<int, char, int>(arg1_node, op, arg2_node);
    for (size_t j = 0; j < lvalue_node; j++) {
      if (nodes[j] == nodes[lvalue_node]) {
        lvalue_node = j;
        break;
      }
    }
    vars[lvalue] = lvalue_node;
  }
  if (vars.count("res") == 0 || vars["res"] == 0) {
    cout << 0 << endl;
    return 0;
  }
  if (get<1>(nodes[vars["res"]]) == '\0') {
    cout << 1 << endl;
    cout << "res=" << names[vars["res"]] << endl;
  } else {
    vector<string> outputs;
    dfs(vars["res"], outputs);
    cout << outputs.size() << endl;
    for (auto &line : outputs) {
      cout << line << endl;
    }
  }
  return 0;
}