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;
using Pii = pair<int, int>;
using Vi = vector<int>;
void run();
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(18);
  run();
  return 0;
}
int uplg(int n) { return 32 - __builtin_clz(n); }
int uplg(ll n) { return 64 - __builtin_clzll(n); }
constexpr ll MOD = 15 * (1 << 27) + 1;
mt19937 rnd(int(time(0)));
struct Zp {
  ll first;
  Zp(ll a = 0) {
    if (a < 0)
      a = a % MOD + MOD;
    else if (a >= MOD * 2)
      a %= MOD;
    else if (a >= MOD)
      a -= MOD;
    first = a;
  }
  Zp operator+(Zp r) const { return first + r.first; }
  Zp operator-(Zp r) const { return first - r.first + MOD; }
  Zp operator*(Zp r) const { return first * r.first; }
  Zp operator/(Zp r) const { return first * r.inv().first; }
  Zp operator-() const { return MOD - first; }
  Zp inv() const { return pow(MOD - 2); }
  Zp pow(ll e) const {
    Zp t = 1, m = *this;
    while (e) {
      if (e & 1) t = t * m;
      e >>= 1;
      m = m * m;
    }
    return t;
  }
  Zp& operator+=(Zp r) { return *this = *this + r; }
  Zp& operator-=(Zp r) { return *this = *this - r; }
  Zp& operator*=(Zp r) { return *this = *this * r; }
  Zp& operator/=(Zp r) { return *this = *this / r; }
  void print() { cerr << first; }
  bool operator<(Zp r) const { return first < r.first; }
};
struct Info {
  string name;
  Zp a, b;
  char op{'x'};
  bool ok{0};
  ;
};
const Zp MULT = rnd();
map<Zp, Info> info;
map<string, Zp> vars;
vector<string> ans, names;
void dfs(Zp what, string name) {
  auto& dep = info[what];
  if (!dep.ok) {
    if (name.empty()) {
      name = names.back();
      names.pop_back();
    }
    dep.name = name;
    dep.ok = 1;
    dfs(dep.a, "");
    dfs(dep.b, "");
    ans.push_back(name + "=" + info[dep.a].name + dep.op + info[dep.b].name);
  } else if (name == "res") {
    ans.push_back("res=" + dep.name);
  }
}
void run() {
  int n;
  cin >> n;
  auto getVar = [&](const string& name) {
    if (vars.count(name)) {
      return vars[name];
    }
    Zp key = rnd();
    vars[name] = key;
    info[key].name = name;
    info[key].ok = 1;
    return key;
  };
  auto combine = [&](const string& a, const string& b, char op) {
    Zp va = getVar(a), vb = getVar(b);
    Zp ret = (va * MULT + vb) * MULT + op;
    info[ret].a = va;
    info[ret].b = vb;
    info[ret].op = op;
    return ret;
  };
  for (int i = (0); i < (n); i++) {
    string line;
    cin >> line;
    int sep = int(line.find("="));
    string dst = line.substr(0, sep), rest = line.substr(sep + 1);
    sep = -1;
    for (int j = (0); j < (int((rest).size())); j++) {
      char c = rest[j];
      if (c == '$' || c == '^' || c == '#' || c == '&') {
        sep = j;
        break;
      }
    }
    if (sep == -1) {
      if (dst != rest) vars[dst] = getVar(rest);
    } else {
      string a = rest.substr(0, sep), b = rest.substr(sep + 1);
      char op = rest[sep];
      vars[dst] = combine(a, b, op);
    }
  }
  for (int i = (0); i < (26); i++)
    for (int j = (0); j < (26); j++)
      for (int k = (0); k < (26); k++)
        for (int l = (0); l < (26); l++) {
          string name = {char(i + 'a'), char(j + 'a'), char(k + 'a'),
                         char(l + 'a')};
          if (vars.count(name)) continue;
          names.push_back(name);
          if (int((names).size()) >= 20000) {
            goto done;
          }
        }
done:
  if (vars.count("res") && info[vars["res"]].name != "res") {
    dfs(vars["res"], "res");
  }
  cout << int((ans).size()) << '\n';
  for (auto& a : (ans)) cout << a << '\n';
}