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>
struct Vertex {
  bool init;
  std::string s;
  Vertex *lhs, *rhs;
  bool calced;
  std::string ssa;
  Vertex() : init(false), lhs(nullptr), rhs(nullptr), calced(false), ssa("") {}
  friend bool operator==(const Vertex &a, const Vertex &b) {
    return (a.init == b.init) && (a.s == b.s) && (a.lhs == b.lhs) &&
           (a.rhs == b.rhs);
  }
};
std::set<std::string> initS;
std::string nextSSA = "acaa";
std::string get_ssa() {
  while (true) {
    nextSSA[0]++;
    for (uint32_t i = 0; i < nextSSA.size(); i++) {
      if (nextSSA[i] > 'z') {
        nextSSA[i + 1]++;
        nextSSA[i] = 'a';
      }
    }
    if (initS.find(nextSSA) == initS.end()) {
      break;
    }
  }
  return nextSSA;
}
const uint32_t MAX_V = 5000;
Vertex vertMem[MAX_V];
Vertex *vertPtr = vertMem;
std::map<std::string, Vertex *> curV;
Vertex *get_vertex() { return vertPtr++; }
Vertex *get_vertex(const std::string &s) {
  auto it = curV.find(s);
  if (it == curV.end()) {
    Vertex *ans = get_vertex();
    ans->ssa = s;
    ans->init = true;
    initS.insert(s);
    std::cerr << "Vertex " << ans - vertMem << " initial " << s << "\n";
    curV[s] = ans;
    return ans;
  } else {
    return it->second;
  }
}
std::vector<std::string> rawP;
void input() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  uint32_t n;
  std::cin >> n;
  rawP.resize(n);
  for (std::string &s : rawP) {
    std::cin >> s;
  }
}
bool is_opr(char c) {
  return (c == '$') || (c == '^') || (c == '#') || (c == '&') || (c == '=');
}
std::vector<std::string> tokenize(const std::string &s) {
  std::vector<std::string> ans;
  std::string curS = "";
  bool op = false;
  for (uint32_t i = 0; i < s.size(); i++) {
    bool curOp = is_opr(s[i]);
    if (op == curOp) {
      curS += s[i];
    } else {
      ans.push_back(curS);
      op = curOp;
      curS = s[i];
    }
  }
  ans.push_back(curS);
  return ans;
}
void build_dag() {
  for (const std::string &s : rawP) {
    auto l = tokenize(s);
    if (l.size() == 3) {
      Vertex *v = get_vertex(l[2]);
      curV[l[0]] = v;
    } else {
      Vertex *v = get_vertex();
      v->s = l[3];
      v->lhs = get_vertex(l[2]);
      v->rhs = get_vertex(l[4]);
      for (Vertex *u = vertMem; u != vertPtr; u++) {
        if ((*u) == (*v)) {
          if (v == u) {
            std::cerr << "vertex " << u - vertMem << ": ";
            std::cerr << "lhs " << u->lhs - vertMem;
            std::cerr << " opr " << u->s;
            std::cerr << " rhs " << u->rhs - vertMem << "\n";
          }
          curV[l[0]] = u;
          break;
        }
      }
    }
  }
}
std::vector<std::string> optP;
void build_program(Vertex *v) {
  if ((v->calced) || (v->init)) {
    return;
  } else {
    build_program(v->lhs);
    build_program(v->rhs);
    if (v->ssa.empty()) {
      v->ssa = get_ssa();
    }
    optP.push_back(v->ssa + "=" + v->lhs->ssa + v->s + v->rhs->ssa);
    v->calced = true;
  }
}
int main() {
  input();
  build_dag();
  auto it = curV.find("res");
  if (it != curV.end()) {
    if ((it->second->init) && (it->second->ssa != "res")) {
      optP.push_back("res=" + it->second->ssa);
    } else {
      it->second->ssa = "res";
      build_program(it->second);
    }
  }
  std::cout << optP.size() << "\n";
  for (const std::string &s : optP) {
    std::cout << s << "\n";
  }
}