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;
using ll = long long;
template <int n, class... T>
typename std::enable_if<(n >= sizeof...(T))>::type __output_tuple(
    std::ostream &, std::tuple<T...> const &) {}
template <int n, class... T>
typename std::enable_if<(n < sizeof...(T))>::type __output_tuple(
    std::ostream &os, std::tuple<T...> const &t) {
  os << (n == 0 ? "" : ", ") << std::get<n>(t);
  __output_tuple<n + 1>(os, t);
}
template <class... T>
std::ostream &operator<<(std::ostream &os, std::tuple<T...> const &t) {
  os << "(";
  __output_tuple<0>(os, t);
  os << ")";
  return os;
}
template <class T, class U>
std::ostream &operator<<(std::ostream &os, std::pair<T, U> const &p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}
template <class T>
std::ostream &operator<<(std::ostream &os, const std::stack<T> &a) {
  os << "{";
  for (auto tmp = a; tmp.size(); tmp.pop())
    os << (a.size() == tmp.size() ? "" : ", ") << tmp.top();
  os << "}";
  return os;
}
template <class T, class Container, class Compare>
std::ostream &operator<<(std::ostream &os,
                         std::priority_queue<T, Container, Compare> a) {
  os << "{ (top) ";
  while (a.size()) os << a.top() << (a.size() == 1 ? "" : ", "), a.pop();
  os << " }";
  return os;
}
template <class T, class Container>
std::ostream &operator<<(std::ostream &os, std::queue<T, Container> a) {
  os << "{ ";
  while (a.size()) os << a.front() << (a.size() == 1 ? "" : ", "), a.pop();
  os << " }";
  return os;
}
template <
    class T,
    class = typename std::iterator_traits<decltype(begin(T()))>::value_type,
    class = typename std::enable_if<!std::is_same<T, std::string>::value>::type>
std::ostream &operator<<(std::ostream &os, const T &a) {
  for (auto ite = begin(a); ite != end(a); ++ite)
    os << (ite == begin(a) ? "" : " ") << *ite;
  return os;
}
inline void hash_combine2(std::size_t &seed, size_t a) {
  seed ^= a + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
inline size_t comball(initializer_list<size_t> l) {
  size_t seed = 0;
  for (auto e : l) {
    hash_combine2(seed, e);
  }
  return seed;
}
template <class T>
inline void hash_combine(std::size_t &seed, const T &v) {
  std::hash<T> hasher;
  seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
using uint = unsigned;
using HASH = tuple<size_t, size_t, size_t>;
enum TYEPS { INPUT, REFERENCE, OP };
struct Data {
  int type = INPUT;
  string name = "";
  HASH hsh;
  char op = '-';
  Data *refer = 0, *l = 0, *r = 0;
  bool operator==(const Data &b) const { return hsh == b.hsh; }
};
set<string> ava;
vector<string> avas;
Data *makeInput(string name) {
  Data *d = new Data;
  d->type = INPUT;
  d->name = name;
  ava.erase(name);
  d->hsh = HASH(hash<string>{}(name), hash<string>{}(name + name),
                hash<char>{}(name[0]));
  return d;
}
Data *makeOp(Data *l, Data *r, char op) {
  Data *d = new Data;
  d->type = OP;
  d->l = l;
  d->r = r;
  d->op = op;
  size_t a, b, c;
  size_t x, y, z;
  tie(a, b, c) = l->hsh;
  tie(x, y, z) = r->hsh;
  size_t seed0 = comball({a, z, hash<string>{}(string(3, op)), y, c});
  size_t seed1 = comball({x, hash<string>{}(string(1, op)), b, c});
  size_t seed2 = comball({a, y, c, hash<char>{}(op), x});
  d->hsh = HASH(seed0, seed1, seed2);
  return d;
}
int n;
int OPN = 4;
char ops[] = {'$', '^', '#', '&'};
map<string, Data *> data;
void reset(string name) {
  if (!data.count(name)) data[name] = makeInput(name);
}
map<tuple<int, string, HASH>, Data *> uni;
int k = 0;
stringstream ans;
set<Data *> used;
void dfs(Data *&p, bool root = 0) {
  if (!p) return;
  auto hs = make_tuple(p->type, p->name + p->op, p->hsh);
  if (uni.count(hs)) {
    p = uni[hs];
    return;
  }
  uni[hs] = p;
  if (used.count(p)) return;
  used.insert(p);
  switch (p->type) {
    case INPUT:
      if (root && p->name != "res") {
        k++;
        ans << "res=" << p->name << "\n";
      }
      break;
    case OP:
      dfs(p->l);
      dfs(p->r);
      string name = "res";
      if (!root) {
        name = avas.back();
        avas.pop_back();
      }
      k++;
      ans << name << "=" << p->l->name << p->op << p->r->name << "\n";
      assert(p->l->name.size());
      assert(p->r->name.size());
      p->name = name;
      break;
  }
}
int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  for (int i = 0; i < 1000; i++) {
    ava.insert("a" + to_string(i));
    ava.insert("b" + to_string(i));
    ava.insert("c" + to_string(i));
  }
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int uku = s.find('=');
    assert(uku != -1);
    string LHS = s.substr(0, uku);
    string RHS = s.substr(uku + 1, int(s.size()) - uku - 1);
    int op = -1;
    string a1, a2;
    for (int o = 0; o < OPN; o++) {
      int id = RHS.find(ops[o]);
      if (id >= 0) {
        op = o;
        a1 = RHS.substr(0, id);
        a2 = RHS.substr(id + 1, int(RHS.size()) - id - 1);
      }
    }
    if (op >= 0) {
      reset(a1);
      reset(a2);
      assert(a1.size());
      assert(a2.size());
      data[LHS] = makeOp(data[a1], data[a2], ops[op]);
    } else {
      reset(RHS);
      data[LHS] = data[RHS];
    }
  }
  reset("res");
  avas = vector<string>(ava.begin(), ava.end());
  dfs(data["res"], 1);
  (42);
  ans << flush;
  cout << k << "\n";
  cout << ans.str();
  return 0;
}