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>
const long long N = 1e6 + 7, mod = 998244353, inf = 1e18;
typedef long long aN[N];
long long cnt = 0, tot = 0;
char s1[1145141], ans[1111][23];
long long readll() {
  long long x = 0, w = 1;
  int c = getchar();
  for (; c < '0' || c > '9'; c - '-' || (w = -w), c = getchar())
    ;
  for (; c >= '0' && c <= '9'; x = x * 10 + (c ^ 48), c = getchar())
    ;
  return x * w;
}
int readchar(int l = '0', int r = 'z') {
  int c = getchar();
  for (; c < l || c > r; c = getchar())
    ;
  return c;
}
long long ssh[N];
struct hash {
  static const long long mod = 1e6 + 7;
  long long val[mod], key[mod], cg[mod];
  long long cnt;
  int count(long long b) const {
    long long now = (b = b ?: 1e6 + 8) % mod, x = 0;
    while (now && key[now] && key[now] != b) now = (now + 2 * x++ + 1) % mod;
    return key[now] == b;
  }
  long long operator[](long long b) const {
    long long now = (b = b ?: 1e6 + 8) % mod, x = 0;
    while (now && key[now] && key[now] != b) now = (now + 2 * x++ + 1) % mod;
    return key[now] == b ? val[now] : 0;
  }
  void clear() {
    while (cnt) key[cnt--] = 0;
  }
  long long& operator[](long long b) {
    long long now = (b = b ?: 1e6 + 8) % mod, x = 0;
    while (now && key[now] && key[now] != b) now = (now + 2 * x++ + 1) % mod;
    return key[now] != b ? key[now] = b, val[cg[++cnt] = now] = 0 : val[now];
  }
} t, t2;
const long long mod1 = 1e9 + 7, mod2 = 1e9 + 9, k1 = 333, k2 = 220,
                mod3 = 998244353;
long long hash_s(const char* s) {
  long long a1 = 0, a2 = 0;
  while (*s) a1 = (a1 * k1 + *s) % mod1, a2 = (a2 * k2 + *s) % mod2, s++;
  return a1 * mod2 + a2;
};
struct lj {
  long long ls, rs, op;
  char s[5];
  lj() {}
  lj(long long l, long long r, long long o, const char* s_)
      : ls(l), rs(r), op(o), s("") {
    strcpy(s, s_);
  }
} ml[N];
void link(const char* s1, const char* s2, const char* s3, char op) {
  long long h1 = hash_s(s1), h2 = hash_s(s2), h3 = hash_s(s3);
  if (!t[h2]) ml[t[h2] = ++cnt] = {0, 0, 0, s2};
  if (op && !t[h3]) ml[t[h3] = ++cnt] = {0, 0, 0, s3};
  ml[++cnt] = op ? (lj){t[h2], t[h3], op, s1} : ml[t[h2]];
  t[h1] = cnt;
}
char nows[] = "aaa`";
void next(char* s) {
  char* t = s;
  while (*t) t++;
  t--;
  while (*t == 'z') *t-- = 'a';
  ++*t;
}
long long solve(long long u) {
  if (ssh[u]) return ssh[u];
  if (!ml[u].ls) return hash_s(ml[u].s) % mod3;
  long long res = ssh[u] =
      (((solve(ml[u].ls) * mod1) + solve(ml[u].rs)) % mod * 137 + ml[u].op) %
      mod3;
  if (t2.count(res)) {
    strcpy(ml[u].s, ml[t2[res]].s);
    return res;
  }
  t2[res] = u;
  do next(nows);
  while (t.count(hash_s(nows)));
  strcpy(ml[u].s, nows);
  sprintf(ans[++tot], "%s=%s%c%s", ml[u].s, ml[ml[u].ls].s, (int)ml[u].op,
          ml[ml[u].rs].s);
  return res;
}
int main() {
  long long n = readll();
  for (register long long i = 1; i <= n; i++) {
    scanf("%s", s1);
    char* s2 = s1;
    while (*s2 != '=') s2++;
    *s2++ = 0;
    char* s3 = s2;
    while ((*s3 >= 'a' && *s3 <= 'z') || (*s3 >= '0' && *s3 <= '9')) s3++;
    char ch = *s3;
    *s3++ = 0, link(s1, s2, s3, ch);
  }
  long long root = t[hash_s("res")];
  if (!root || !ml[root].ls)
    if (root && strcmp(ml[root].s, "res"))
      printf("1\nres=%s", ml[root].s);
    else
      puts("0");
  else {
    solve(root), printf("%lld\n", tot);
    for (register long long i = 1; i <= tot - 1; i++) puts(ans[i]);
    char* s = ans[tot];
    while (*s++ != '=')
      ;
    printf("res=%s\n", s);
  }
  return 0;
}