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>
const int MAXN = 1010;
inline bool issym(char x) {
  return x == '$' || x == '^' || x == '#' || x == '&' || x == '=';
}
std::vector<std::string> tokenize(std::string buf) {
  buf += '$';
  int lst = 0;
  std::vector<std::string> res;
  for (int i = 0, sz = buf.length(); i != sz; ++i) {
    if (issym(buf[i])) {
      res.push_back(buf.substr(lst, i - lst));
      if (i != sz - 1) res.push_back(buf.substr(i, 1));
      lst = i + 1;
    }
  }
  return res;
}
struct edge {
  std::string opt;
  int lhs, rhs;
};
std::map<int, edge> frm;
std::map<std::string, int> pool;
int idx;
std::map<int, std::string> name;
std::set<std::string> pragma;
void alloc(std::string x) {
  if (!pool.count(x)) {
    pool[x] = ++idx;
    name[idx] = x;
    pragma.insert(x);
  }
}
std::string getbyid(int x) {
  static char buf[10];
  sprintf(buf, "d%d", x);
  return std::string(buf);
}
std::string getn(int x) {
  if (!name.count(x)) {
    static int cnt = 0;
    while (pragma.count(getbyid(cnt))) ++cnt;
    name[x] = getbyid(cnt++);
  }
  return name[x];
}
std::vector<std::string> ans;
std::set<int> vis;
void dfs(int u) {
  if (vis.count(u)) return;
  vis.insert(u);
  if (!frm.count(u)) return;
  dfs(frm[u].lhs);
  dfs(frm[u].rhs);
  ans.push_back(getn(u) + "=" + getn(frm[u].lhs) + frm[u].opt +
                getn(frm[u].rhs));
}
int main() {
  std::ios_base::sync_with_stdio(false), std::cin.tie(0);
  int n;
  std::cin >> n;
  while (n-- > 0) {
    std::string x;
    std::cin >> x;
    std::vector<std::string> ret = tokenize(x);
    std::string lval = ret[0], lhs = ret[2], opt, rhs;
    alloc(lhs);
    if (ret.size() > 3) {
      opt = ret[3], rhs = ret[4];
      alloc(rhs);
      std::string full = getn(pool[lhs]) + opt + getn(pool[rhs]);
      if (pool.count(full)) {
        pool[lval] = pool[full];
      } else {
        ++idx;
        frm[idx].opt = opt;
        frm[idx].lhs = pool[lhs];
        frm[idx].rhs = pool[rhs];
        pool[full] = pool[lval] = idx;
      }
    } else {
      pool[lval] = pool[lhs];
    }
  }
  if (!pool.count("res")) return std::cout << 0 << std::endl, 0;
  int res = pool["res"];
  if (!frm.count(res) && name[res] != "res") ans.push_back("res=" + name[res]);
  name[res] = "res";
  dfs(res);
  std::cout << ans.size() << '\n';
  for (auto t : ans) std::cout << t << '\n';
  return 0;
}