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 char ops[] = "$^#&";
struct symbol;
map<uint64_t, symbol*> symequiv;
vector<string> program;
set<string> names;
void init_names() {
  char ch[5] = {};
  for (ch[0] = 'a'; ch[0] <= 'z'; ch[0]++)
    for (ch[1] = 'a'; ch[1] <= 'z'; ch[1]++)
      for (ch[2] = 'a'; ch[2] <= 'z'; ch[2]++)
        for (ch[3] = 'a'; ch[3] <= 'z'; ch[3]++) names.insert(ch);
}
string alloc_name() {
  string ret = *names.begin();
  names.erase(names.begin());
  return ret;
}
mt19937_64 rangen(time(NULL));
std::hash<string> strhash;
struct symbol {
  int type;
  string name;
  uint64_t hash;
  symbol *lhs, *rhs;
  symbol(string name) : type(-1), name(name), hash(rangen()) {
    ((void)0);
    names.erase(name);
    symequiv[hash] = this;
  }
  symbol(int op, symbol* lhs, symbol* rhs)
      : type(op),
        hash(strhash(to_string(lhs->hash) + char('A' + op) +
                     to_string(rhs->hash))),
        lhs(lhs),
        rhs(rhs) {
    ((void)0);
    symequiv[hash] = this;
  }
  void gen(bool isres = false) {
    ((void)0);
    if (isres and type == -1 and name != "res") {
      program.push_back("res=" + name);
      return;
    }
    if (name.size()) return;
    lhs = symequiv[lhs->hash];
    lhs->gen();
    rhs = symequiv[rhs->hash];
    rhs->gen();
    name = isres ? "res" : alloc_name();
    program.push_back(name + "=" + lhs->name + ops[type] + rhs->name);
  }
};
vector<symbol> symbols;
map<string, symbol*> symtbl;
symbol* getsym(string str) {
  if (symtbl.count(str)) return symtbl[str];
  symbols.emplace_back(str);
  return symtbl[str] = &symbols.back();
}
void parse(char instr[]) {
  char *pos = strchr(instr, '='), *posop;
  *(pos++) = '\0';
  for (int i = 0; i < int(4); i++) {
    if (!(posop = strchr(pos, ops[i]))) continue;
    *(posop++) = '\0';
    symbols.emplace_back(i, getsym(pos), getsym(posop));
    symtbl[instr] = &symbols.back();
    return;
  }
  symbol* sym = getsym(pos);
  symtbl[instr] = sym;
}
int main() {
  init_names();
  symbols.reserve(10240);
  int n;
  scanf("%d", &n);
  for (int i = 0; i < int(n); i++) {
    char instr[256];
    scanf("%s", instr);
    parse(instr);
  }
  getsym("res")->gen(true);
  cout << program.size() << endl;
  for (string str : program) cout << str << endl;
  return 0;
}