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;
const int N = 2e5 + 10;
const int mo = 1e9 + 7;
int tot, l[N], r[N];
string is[N];
bool v[N];
char op[N];
bool ic(char c) {
  return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
         (c >= '0' && c <= '9');
}
bool opr(char c) {
  return (c == '$') || (c == '^') || (c == '#') || (c == '&');
}
void ins(string &s) {
  ++s[3];
  for (int i = (3); i >= (1); --i)
    if (s[i] > 'z')
      ++s[i - 1], s[i] = 'a';
    else
      return;
}
void dfs(int x) {
  if (v[x]) return;
  v[x] = 1;
  if (l[x]) dfs(l[x]);
  if (r[x]) dfs(r[x]);
}
int main() {
  int n;
  cin >> n;
  map<string, int> id;
  map<pair<pair<int, int>, char>, int> p;
  for (int i = (1); i <= (n); ++i) {
    string a, b, c;
    char C = getchar();
    while (!ic(C)) C = getchar();
    for (; C != '='; C = getchar()) a += C;
    for (C = getchar(); ic(C); C = getchar()) b += C;
    if (!id.count(b)) {
      id[b] = ++tot;
      is[tot] = b;
    }
    if (opr(C)) {
      char OP = C;
      for (C = getchar(); ic(C); C = getchar()) c += C;
      if (!id.count(c)) {
        id[c] = ++tot;
        is[tot] = c;
      }
      pair<pair<int, int>, char> pt = {{id[b], id[c]}, OP};
      if (p.count(pt))
        id[a] = p[pt];
      else {
        p[pt] = ++tot;
        l[tot] = id[b];
        r[tot] = id[c];
        op[tot] = OP;
        id[a] = tot;
      }
    } else
      id[a] = id[b];
  }
  if (!id.count("res") || is[id["res"]] == "res") return printf("0\n"), 0;
  if (!is[id["res"]].empty())
    return cout << "1\nres=" << is[id["res"]] << '\n', 0;
  is[id["res"]] = "res";
  dfs(id["res"]);
  set<string> vb;
  int ans = 1;
  for (int i = (1); i <= (tot); ++i)
    if (v[i]) {
      if (!is[i].empty())
        vb.insert(is[i]);
      else
        ++ans;
    }
  string nw = "aaaa";
  while (vb.count(nw)) ins(nw);
  cout << ans << '\n';
  for (int i = (1); i <= (tot); ++i)
    if (v[i] && l[i]) {
      if (is[i].empty()) {
        is[i] = nw;
        ins(nw);
      }
      cout << is[i] << '=' << is[l[i]];
      if (op[i]) cout << op[i] << is[r[i]];
      cout << '\n';
    }
}