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;
inline void read(int &x) {
  int v = 0, f = 1;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = (c & 15);
  while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15);
  x = v * f;
}
inline void read(long long &x) {
  long long v = 0ll, f = 1ll;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = (c & 15);
  while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15);
  x = v * f;
}
inline void readc(char &x) {
  char c;
  while (((c = getchar()) == ' ') || c == '\n')
    ;
  x = c;
}
const string opch = "$^#&";
int n, i, j, op[1005], cnt, tmp, vis[4005];
map<pair<int, int>, int> mp[4];
map<char, int> opid;
string name[4005], s1[1005], s2[4005], s3[4005];
map<string, int> cur;
int lc[4005], rc[4005], opt[4005];
vector<string> ans;
string rnd() {
  string st;
  int x = rand() % 26;
  st.push_back(x + 'a');
  x = rand() % 36;
  if (x < 26)
    st.push_back(x + 'a');
  else
    st.push_back(x - 26 + '0');
  x = rand() % 36;
  if (x < 26)
    st.push_back(x + 'a');
  else
    st.push_back(x - 26 + '0');
  x = rand() % 36;
  if (x < 26)
    st.push_back(x + 'a');
  else
    st.push_back(x - 26 + '0');
  return st;
}
void upd(string st) {
  if (!cur.count(st)) {
    cur[st] = ++cnt;
    name[cnt] = st;
  }
}
int f(int x, int a, int b) {
  if (mp[x].count(make_pair(a, b))) return mp[x][make_pair(a, b)];
  lc[tmp + 1] = a;
  rc[tmp + 1] = b;
  opt[tmp + 1] = x;
  return mp[x][make_pair(a, b)] = ++tmp;
}
void dfs(int x) {
  if (vis[x]) return;
  vis[x] = 1;
  if (lc[x]) {
    dfs(lc[x]);
    dfs(rc[x]);
    ans.push_back(name[x] + "=" + name[lc[x]] + opch[opt[x]] + name[rc[x]]);
  }
}
int main() {
  memset(opt, -1, sizeof(opt));
  srand(time(NULL));
  ios_base::sync_with_stdio(false);
  ;
  opid['$'] = 0;
  opid['^'] = 1;
  opid['#'] = 2;
  opid['&'] = 3;
  cin >> n;
  for (((j)) = (1); ((j)) <= ((n)); ((j))++) {
    string st;
    cin >> st;
    string s1, s2, s3;
    s1 = st.substr(0, st.find('='));
    st = st.substr(st.find('=') + 1);
    for (((i)) = (0); ((i)) <= (((int)(st.size())) - 1); ((i))++) {
      if (!islower(st[i]) && !isupper(st[i]) && !isdigit(st[i])) {
        break;
      }
      s2.push_back(st[i]);
    }
    if (i == st.size()) {
      op[j] = -1;
    } else {
      op[j] = opid[st[i]];
      s3 = st.substr(i + 1);
    }
    ::s1[j] = s1;
    ::s2[j] = s2;
    ::s3[j] = s3;
  }
  for (((i)) = (1); ((i)) <= ((n)); ((i))++) {
    upd(s1[i]);
    upd(s2[i]);
    if (op[i] != -1) upd(s3[i]);
  }
  tmp = cnt;
  for (((i)) = (1); ((i)) <= ((n)); ((i))++) {
    string st;
    st = rnd();
    while (cur.count(st)) st = rnd();
    upd(st);
  }
  for (((i)) = (1); ((i)) <= ((n)); ((i))++) {
    if (op[i] == -1) {
      cur[s1[i]] = cur[s2[i]];
    } else {
      cur[s1[i]] = f(op[i], cur[s2[i]], cur[s3[i]]);
    }
  }
  if (!cur.count("res")) {
    puts("0");
    return 0;
  }
  string tt = name[cur["res"]];
  name[cur["res"]] = "res";
  dfs(cur["res"]);
  if (ans.empty() && tt != "res") {
    printf("1\nres=%s\n", tt.c_str());
    return 0;
  }
  printf("%d\n", ans.size());
  for (__typeof((ans).begin()) it = (ans).begin(); it != (ans).end(); it++)
    puts(it->c_str());
  return 0;
}