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 NUM_LETTERS = 37,
          NUM_NAMES =
              (NUM_LETTERS - 11) * NUM_LETTERS * NUM_LETTERS * NUM_LETTERS,
          MAXN = 4006, NAME_SIZE = 4;
int letterToInt[300];
char intToLetter[NUM_LETTERS];
int nameToInt(string str) {
  while (((int)str.size()) < NAME_SIZE) str += ' ';
  int ans = 0;
  for (int i = 0; i <= 3; ++i)
    ans = ans * NUM_LETTERS + letterToInt[(int)str[i]];
  return ans;
}
string intToName(int code) {
  string str;
  for (int _ = 0; _ < 4; ++_, code /= NUM_LETTERS)
    str = intToLetter[code % NUM_LETTERS] + str;
  while (str.back() == ' ') str.pop_back();
  return str;
}
int opToCode[300];
char codeToOp[4] = {'#', '$', '^', '&'};
int n;
int nameToVar[NUM_NAMES], varToName[MAXN], expp[MAXN], ptr = 1, curName = 0;
int varOfExp[4 * MAXN * MAXN];
bool done[MAXN];
vector<string> outs;
int getExp(int i1, int i2, int op) { return i1 + MAXN * (i2 + MAXN * op); }
void add(int name) {
  nameToVar[varToName[ptr] = name] = ptr;
  ++ptr;
}
void read() {
  string line;
  cin >> line;
  int asgn = 0;
  for (; line[asgn] != '='; ++asgn)
    ;
  int opI = 0;
  for (; opI < ((int)line.size()) && opToCode[(int)line[opI]] < 0; ++opI)
    ;
  if (opI == ((int)line.size())) {
    int lval = nameToInt(line.substr(0, asgn));
    int rval = nameToInt(line.substr(asgn + 1));
    if (!nameToVar[rval]) add(rval);
    nameToVar[lval] = nameToVar[rval];
  } else {
    int lval = nameToInt(line.substr(0, asgn));
    int val1 = nameToInt(line.substr(asgn + 1, opI - asgn - 1));
    int val2 = nameToInt(line.substr(opI + 1));
    if (!nameToVar[val1]) add(val1);
    if (!nameToVar[val2]) add(val2);
    int curExp =
        getExp(nameToVar[val1], nameToVar[val2], opToCode[(int)line[opI]]);
    if (varOfExp[curExp]) {
      nameToVar[lval] = varOfExp[curExp];
    } else {
      int lvar = nameToVar[lval] = ptr++;
      varOfExp[expp[lvar] = curExp] = lvar;
    }
  }
}
void declare(int var) {
  if (varToName[var] < 0) {
    while (nameToVar[curName]) ++curName;
    varToName[var] = curName++;
  }
  if (done[var] || !expp[var]) return;
  done[var] = 1;
  int cur = expp[var], i1, i2, op;
  i1 = cur % MAXN, cur /= MAXN, i2 = cur % MAXN, cur /= MAXN, op = cur;
  declare(i1);
  declare(i2);
  string str;
  str += intToName(varToName[var]);
  str += '=';
  str += intToName(varToName[i1]);
  str += codeToOp[op];
  str += intToName(varToName[i2]);
  outs.emplace_back(str);
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  for (int i = 0; i <= NUM_LETTERS - 1; ++i) intToLetter[i] = -1;
  for (int i = 0; i <= 25; ++i) intToLetter[i] = i + 'a';
  for (int i = 0; i <= 9; ++i) intToLetter[i + 26] = i + '0';
  intToLetter[36] = ' ';
  for (int i = 0; i <= NUM_LETTERS - 1; ++i)
    letterToInt[(int)intToLetter[i]] = i;
  for (int i = 0; i <= 299; ++i) opToCode[i] = -1;
  opToCode['#'] = 0, opToCode['$'] = 1, opToCode['^'] = 2, opToCode['&'] = 3;
  for (int i = 0; i <= MAXN - 1; ++i) varToName[i] = -1;
  cin >> n;
  for (int _ = 0; _ <= n - 1; ++_) read();
  if (!nameToVar[nameToInt("res")] ||
      intToName(varToName[nameToVar[nameToInt("res")]]) == "res")
    return cout << 0 << endl, 0;
  if (!expp[nameToVar[nameToInt("res")]])
    return cout << "1\nres="
                << intToName(varToName[nameToVar[nameToInt("res")]]) << endl,
           0;
  varToName[nameToVar[nameToInt("res")]] = nameToInt("res");
  declare(nameToVar[nameToInt("res")]);
  cout << ((int)outs.size()) << '\n';
  for (auto &x : outs) cout << x << '\n';
  return 0;
}