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 maxn = 3010, mod = 1e9 + 9, P = 1e6 + 3;
const long long inf = 1e18;
map<string, int> mp;
string who[maxn];
int C, L[maxn], R[maxn];
vector<int> v[maxn];
int what[maxn];
bool mark[maxn];
void dfs(int u) {
  if (mark[u] == 1) return;
  mark[u] = 1;
  if (L[u] == -1) {
    int &hsh = what[u];
    for (int i = 0; i < int((who[u]).size()); i++)
      hsh = (1ll * hsh * P + who[u][i]) % mod;
  } else {
    dfs(L[u]);
    dfs(R[u]);
    int &hsh = what[u];
    hsh = what[L[u]];
    for (int i = 0; i < int((who[u]).size()); i++)
      hsh = (1ll * hsh * P % mod * 117 + who[u][i]) % mod;
    hsh = (1ll * hsh * P % mod * 101 * 17 + what[R[u]]) % mod;
  }
}
vector<string> ans;
map<int, string> name;
int Cn = 0;
char CC = 'a';
inline string New() {
  string s;
  s.push_back(CC);
  if (Cn == 1000) CC++, Cn = 0;
  int x = Cn++;
  for (int i = 0; i < 3; i++) s += '0' + (x % 10), x /= 10;
  if (mp.count(s)) return New();
  return s;
}
void dfs2(int u) {
  if (name.count(what[u])) return;
  if (L[u] == -1) {
    name[what[u]] = who[u];
  } else {
    dfs2(L[u]);
    dfs2(R[u]);
    string nm = New();
    if (u == mp["res"]) nm = "res";
    ans.push_back(nm + "=" + name[what[L[u]]] + who[u] + name[what[R[u]]]);
    name[what[u]] = nm;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    string s1, s2, s3;
    string op;
    int pt = 0;
    while (s[pt] != '=') s1 += s[pt++];
    pt++;
    while (pt < int((s).size()) && s[pt] != '&' && s[pt] != '#' &&
           s[pt] != '^' && s[pt] != '$')
      s2 += s[pt++];
    if (pt == int((s).size())) {
      if (!mp.count(s2)) who[C] = s2, L[C] = -1, mp[s2] = C++;
      mp[s1] = mp[s2];
    } else {
      op.push_back(s[pt++]);
      while (pt < int((s).size())) s3 += s[pt++];
      if (!mp.count(s2)) who[C] = s2, L[C] = -1, mp[s2] = C++;
      if (!mp.count(s3)) who[C] = s3, L[C] = -1, mp[s3] = C++;
      who[C] = op, L[C] = mp[s2], R[C] = mp[s3], mp[s1] = C++;
    }
  }
  if (!mp.count("res")) {
    return cout << 0 << endl, 0;
  }
  dfs(mp["res"]);
  dfs2(mp["res"]);
  if (int((ans).size()) == 0) {
    if (who[mp["res"]] == "res")
      return cout << 0 << endl, 0;
    else
      return cout << "1\n"
                  << "res=" << who[mp["res"]] << endl,
             0;
  } else {
    cout << int((ans).size()) << "\n";
    for (string &str : ans) {
      cout << str << "\n";
    }
  }
  return 0;
}