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;
long long read() {
  int f = 1;
  long long res = 0;
  char ch;
  do {
    ch = getchar();
    if (ch == '-') f = -f;
  } while (ch < '0' || ch > '9');
  do {
    res = res * 10 + ch - '0';
    ch = getchar();
  } while (ch >= '0' && ch <= '9');
  return f == 1 ? res : -res;
}
const int N = 5010;
const int INF = 1000000000;
int n, m, q;
int mod = 998244353;
int head[N], to[N << 1], nxt[N << 1], color[N << 1], tot;
char str[N];
int A[N], B[N];
map<string, int> word2node;
map<tuple<char, int, int>, int> operators;
vector<string> origin_var;
vector<tuple<char, int, int>> nodes;
map<int, string> newVar;
vector<string> res;
void addEdge(int u, int v) {
  tot++;
  nxt[tot] = head[u];
  to[tot] = v;
  head[u] = tot;
}
long long myPow(long long a, int b) {
  if (b == 0) return 1;
  long long ans = myPow(a, b / 2);
  ans *= ans;
  ans %= mod;
  if (b % 2 == 1) {
    ans *= a;
    ans %= mod;
  }
  return ans;
}
void addMod(int &a, int b) {
  a += b;
  a %= mod;
}
int mul(int a, int b) { return 1LL * a * b % mod; }
long long mmin(long long a, long long b) { return a < b ? a : b; }
long long mmax(long long a, long long b) { return a > b ? a : b; }
bool contain(int set, int i) { return (set & (1 << i)) > 0; }
int countOne(int set) {
  int res = 0;
  while (set) {
    res++;
    set &= set - 1;
  }
  return res;
}
bool isOp(char ch) {
  for (char c : "$^#&")
    if (c == ch) return true;
  return false;
}
string fresh() {
  string s = "aaaa";
  while (word2node.count(s)) {
    for (int i = 0; i < 4; i++) s[i] = 'a' + rand() % 26;
  }
  word2node[s] = -1;
  return s;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  tot = 0;
  auto addNode = [&](string word) {
    origin_var.push_back(word);
    nodes.push_back(make_tuple('=', -1, tot));
    word2node[word] = tot++;
  };
  while (n--) {
    cin >> str;
    string ans(str);
    int ii = 0;
    while (ans[ii] != '=') ii++;
    string a = ans.substr(0, ii);
    ans = ans.substr(ii + 1);
    ii = 0;
    for (ii = 0; ii < ans.length(); ii++) {
      if (isOp(ans[ii])) break;
    }
    if (ii == ans.length()) {
      string b = ans;
      if (!word2node.count(b)) {
        addNode(b);
      }
      word2node[a] = word2node[b];
    } else {
      string b = ans.substr(0, ii);
      string c = ans.substr(ii + 1);
      char op = ans[ii];
      if (!word2node.count(b)) {
        addNode(b);
      }
      if (!word2node.count(c)) {
        addNode(c);
      }
      tuple<char, int, int> tpl = make_tuple(op, word2node[b], word2node[c]);
      if (!operators.count(tpl)) {
        nodes.push_back(tpl);
        origin_var.push_back(a);
        operators[tpl] = tot++;
      }
      word2node[a] = operators[tpl];
    }
  }
  if (!word2node.count("res")) {
    cout << 0 << endl;
    return 0;
  }
  function<string(int)> rec = [&](int cur) {
    if (newVar.count(cur)) return newVar[cur];
    char op;
    int a, b;
    tie(op, a, b) = nodes[cur];
    if (op == '=') return origin_var[cur];
    string stra = rec(a);
    string strb = rec(b);
    string str = (cur == word2node["res"]) ? "res" : fresh();
    res.push_back(str + "=" + stra + op + strb);
    newVar[cur] = str;
    return str;
  };
  string lst = rec(word2node["res"]);
  if (lst != "res") res.push_back("res=" + lst);
  cout << res.size() << endl;
  for (string a : res) cout << a.c_str() << endl;
  return 0;
}