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 std::cin;
using std::cout;
using std::string;
using std::vector;
const int maxn = 200200;
struct name {
  int id;
  inline name() {}
  inline name(string s) {
    s.resize(4);
    id = *(int *)s.data();
  }
};
inline int operator<(const name &x, const name &y) { return x.id < y.id; }
inline int operator!=(const name &x, const name &y) { return x.id != y.id; }
static std::mt19937 rd(time(0));
struct val_tree {
  static const int mod = 998244353;
  int hash_val;
  int is_leave;
  char oper_type;
  val_tree *left, *right;
  name id;
  inline val_tree() {
    hash_val = rd() % mod;
    is_leave = 1;
    oper_type = 0;
    left = right = nullptr;
    id.id = 0;
  }
  inline val_tree(val_tree *le, char op, val_tree *ri) {
    hash_val = ((long long)le->hash_val * 234234 +
                (long long)ri->hash_val * 114514 + op) %
               mod;
    is_leave = 0;
    oper_type = op;
    left = le;
    right = ri;
    id.id = 0;
  }
};
std::map<name, val_tree *> map;
std::map<int, name> oper;
vector<string> operators;
std::set<name> set = {name("res")};
inline name gen() {
  do {
    string s;
    for (int i = 0; i < 4; ++i) s += char(rd() % 26 + 'a');
    name x(s);
    if (!set.count(x)) {
      set.emplace(x);
      return x;
    }
  } while (1);
}
string to_string(name x) {
  char ch[5] = {};
  memcpy(ch, &x, 4);
  return (string)ch;
}
inline name dfs(val_tree *x, bool is_last = 0) {
  if (oper.count(x->hash_val)) {
    return oper[x->hash_val];
  }
  name le = dfs(x->left), ri = dfs(x->right);
  name now = is_last ? name("res") : gen();
  operators.emplace_back(to_string(now) + "=" + to_string(le) + x->oper_type +
                         to_string(ri));
  return oper[x->hash_val] = now;
}
inline val_tree *get(name x) {
  if (map.count(x)) return map[x];
  val_tree *o = map[x] = new val_tree();
  o->id = x;
  set.emplace(x);
  oper[o->hash_val] = x;
  return o;
}
inline bool is_oper(char x) {
  return x == '=' || x == '$' || x == '^' || x == '#' || x == '&';
}
inline vector<string> split(string x) {
  vector<string> vec;
  string now;
  for (char i : x) {
    if (is_oper(i)) {
      vec.emplace_back(now);
      now = i;
      vec.emplace_back(now);
      now = "";
    } else {
      now += i;
    }
  }
  vec.emplace_back(now);
  return vec;
}
inline void do_it(string x) {
  vector<string> vc = split(x);
  if (vc.size() == 3) {
    if (vc[0] != vc[2]) map[name(vc[0])] = get(name(vc[2]));
  } else {
    val_tree *v0 = get(name(vc[2])), *v1 = get(name(vc[4]));
    map[name(vc[0])] = new val_tree(v0, vc[3].back(), v1);
  }
}
int main() {
  std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    do_it(s);
  }
  if (map.count(name("res"))) {
    name out = dfs(map[name("res")], 1);
    if (operators.empty() && out != name("res")) {
      cout << 1 << '\n';
      cout << "res=" << to_string(out) << '\n';
      return 0;
    }
    cout << operators.size() << '\n';
    for (string i : operators) {
      cout << i << '\n';
    }
  } else {
    cout << 0 << '\n';
  }
}