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;
int totalVariables, parent[3001];
vector<vector<int> > adj(3001);
set<char> operators{'#', '$', '^', '&'};
char operations[3001];
map<string, int> variableIndex;
map<tuple<char, int, int>, int> operationsIndex;
string variables[3001];
bool visited[3001];
vector<string> ans;
int AddVariable(string s) {
  variableIndex[s] = totalVariables;
  variables[totalVariables] = s;
  return totalVariables++;
}
int GetVariableIndex(string s) {
  auto it = variableIndex.find(s);
  if (it != variableIndex.end()) {
    return it->second;
  }
  return AddVariable(s);
}
int GetOperationsIndex(char c, int i, int j, int k) {
  tuple<char, int, int> t = make_tuple(c, i, j);
  auto it = operationsIndex.find(t);
  if (it != operationsIndex.end()) {
    return it->second;
  }
  operationsIndex[t] = k;
  return k;
}
void DFS(int i) {
  visited[i] = true;
  if (adj[i].empty()) {
    return;
  }
  for (int j : adj[i]) {
    if (visited[j]) {
      continue;
    }
    DFS(j);
  }
  int j = adj[i][0], k = adj[i].back();
  if (operations[i] == '=') {
    parent[i] = parent[j];
    return;
  }
  j = parent[j], k = parent[k];
  parent[i] = GetOperationsIndex(operations[i], j, k, i);
  if (parent[i] != i) {
    return;
  }
  string a = variables[i], b = variables[j], c = variables[k];
  string ansx = a + "=" + b + string(1, operations[i]) + c;
  ans.push_back(ansx);
}
int main() {
  int n;
  cin >> n;
  while (n--) {
    string s;
    cin >> s;
    int x = 0;
    for (; x < s.size() && s[x] != '='; ++x)
      ;
    int y = x + 1;
    for (; y < s.size() && operators.count(s[y]) == 0; ++y)
      ;
    int k = y == s.size() ? -1 : GetVariableIndex(string(s, y + 1));
    int j = GetVariableIndex(string(s, x + 1, y - x - 1));
    int i = AddVariable(string(s, 0, x));
    operations[i] = k >= 0 ? s[y] : '=';
    adj[i].push_back(j);
    if (k >= 0) {
      adj[i].push_back(k);
    }
  }
  if (variableIndex.count("res") == 0) {
    printf("0\n");
    return 0;
  }
  int root = variableIndex["res"];
  for (; adj[root].size() == 1 && !adj[adj[root].back()].empty();
       root = adj[root].back())
    ;
  variables[root] = "res";
  for (int i = 0, t = 0; i < totalVariables; ++i) {
    parent[i] = i;
    if (adj[i].empty() || i == root) {
      continue;
    }
    string s;
    while (true) {
      for (int x = t, i = 0; i < 3; ++i, x /= 26) {
        s.push_back('a' + (x % 26));
      }
      ++t;
      if (variableIndex.count(s)) {
        s.clear();
      } else {
        break;
      }
    }
    variables[i] = s;
  }
  DFS(root);
  if (parent[root] != root && variables[root] != variables[parent[root]]) {
    ans.push_back(variables[root] + "=" + variables[parent[root]]);
  }
  cout << ans.size() << '\n';
  for (string s : ans) {
    cout << s << '\n';
  }
  return 0;
}