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 readInt() {
  int x;
  if (scanf(" %d", &x) != EOF) return x;
  return -1;
}
long long int readLint() {
  long long int x;
  if (cin >> x) return x;
  return -1;
}
string readString() {
  string s;
  if (cin >> s) return s;
  return "";
}
struct Operation {
  char op;
  int left, right;
  Operation(char op, int left, int right) : op(op), left(left), right(right) {}
  bool equals(const Operation& that) {
    return op == that.op && left == that.left && right == that.right;
  }
  void print() { printf("{op = %c, left = %d, right = %d}", op, left, right); }
};
const string RES("res");
struct Program {
  vector<Operation> nodes;
  set<string> allNames;
  map<int, int> values;
  map<int, string> varNames;
  map<string, int> varIndex;
  Program() {
    for (int i = 0; i < 26; ++i)
      for (int j = 0; j < 26; ++j)
        for (int k = 0; k < 10; ++k) {
          string cur = "";
          cur += (char)('a' + i);
          cur += (char)('a' + j);
          cur += (char)('a' + k);
          allNames.insert(cur);
        }
  }
  void readProgram(int numLines) {
    for (int i = 0; i < numLines; ++i) {
      interpretLine(readString());
    }
  }
  void writeProgram() {
    int root = getVarIndex(RES);
    vector<string> ret = write(root);
    cout << ret.size() << endl;
    for (auto& line : ret) cout << line << endl;
  }
  vector<string> write(int root) {
    int a = getValue(root);
    if (a == root) {
      return vector<string>();
    }
    if (a < 0) {
      string name = varNames[a];
      return vector<string>(1, "res=" + name);
    }
    vector<string> ret;
    vector<string> names(nodes.size(), "");
    writeInto(ret, names, a, true);
    return ret;
  }
  string getName(vector<string>& names, int idx) {
    if (idx < 0) return varNames[idx];
    return names[idx];
  }
  string generateName() {
    while (true) {
      string cand = *allNames.begin();
      allNames.erase(allNames.begin());
      if (!varIndex.count(cand)) return cand;
    }
    assert(false);
  }
  void writeInto(vector<string>& ret, vector<string>& names, int idx,
                 bool first = false) {
    if (idx < 0) {
      return;
    }
    string& R = names[idx];
    if (!R.empty()) return;
    if (first) {
      R = "res";
    } else {
      R = generateName();
    }
    Operation op = nodes[idx];
    writeInto(ret, names, op.left);
    writeInto(ret, names, op.right);
    string line = R + "=";
    line += getName(names, op.left);
    line += op.op;
    line += getName(names, op.right);
    ret.push_back(line);
  }
  int getVarIndex(const string& s) {
    auto it = varIndex.find(s);
    if (it != varIndex.end()) return it->second;
    int idx = -1 - (int)(varIndex.size());
    varIndex[s] = idx;
    varNames[idx] = s;
    values[idx] = idx;
    return idx;
  }
  int getValue(int x) { return values[x]; }
  void interpret(int aIdx, int bIdx) { values[aIdx] = getValue(bIdx); }
  void interpret(int aIdx, char c, string& left, string& right) {
    int lIdx = getVarIndex(left);
    int rIdx = getVarIndex(right);
    Operation op(c, getValue(lIdx), getValue(rIdx));
    int opIdx = -1;
    for (int i = 0; i < nodes.size(); ++i)
      if (nodes[i].equals(op)) {
        opIdx = i;
        break;
      }
    if (opIdx < 0) {
      opIdx = nodes.size();
      nodes.push_back(op);
    }
    values[aIdx] = opIdx;
  }
  void interpretLine(string s) {
    int eq = s.find_first_of("=");
    assert(eq >= 0);
    string a = s.substr(0, eq);
    int aIdx = getVarIndex(a);
    string rem = s.substr(eq + 1);
    int idx = rem.find_first_of("$^#&");
    if (idx >= 0) {
      string left = rem.substr(0, idx);
      string right = rem.substr(idx + 1);
      char c = rem[idx];
      interpret(aIdx, c, left, right);
    } else {
      string b = rem;
      int bIdx = getVarIndex(b);
      interpret(aIdx, bIdx);
    }
  }
  void print() {
    for (auto& var : varIndex) {
      printf("Variable %s. Index = %d, value = %d\n", var.first.c_str(),
             var.second, getValue(var.second));
    }
    for (int i = 0; i < nodes.size(); ++i) {
      printf("Node %d: ", i);
      nodes[i].print();
      cout << endl;
    }
  }
};
struct SingleCase {
  bool solveCase() {
    int n = readInt();
    if (n < 0) return false;
    Program program;
    program.readProgram(n);
    program.writeProgram();
    return true;
  }
};
int main() {
  while (SingleCase().solveCase()) {
  }
}