#include <bits/stdc++.h>
using namespace std;
bool debug = true;
template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2> ptt) {
  os << ptt.first << "," << ptt.second;
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vt) {
  os << "{";
  for (int i = 0; i < vt.size(); i++) {
    os << vt[i] << " ";
  }
  os << "}";
  return os;
}
int n;
string code[1005];
struct Node {
  long long l, r;
  char op;
  Node() {}
  Node(long long a, long long b, char c) {
    l = a;
    r = b;
    op = c;
  }
};
map<string, long long> val;
map<long long, string> hsh2var;
map<long long, Node> node;
map<long long, string> name;
set<string> inUse;
const long long p = 999983;
long long getHash(string& r) {
  long long hsh = 0;
  for (int i = 0; i < r.size(); i++) {
    hsh = hsh * p + r[i];
  }
  return hsh;
}
long long getVal(string& r) {
  if (val.count(r)) {
    return val[r];
  } else {
    long long hsh = getHash(r);
    val[r] = hsh;
    if (hsh2var.count(hsh)) {
      assert(false);
    }
    hsh2var[hsh] = r;
    inUse.insert(r);
    return hsh;
  }
}
string curName = "aaaa";
string getName() {
st:
  int p = 3;
  while (true) {
    if (p == -1) {
      assert(false);
    }
    curName[p]++;
    if (curName[p] > 'z') {
      curName[p] = 'a';
      p--;
    } else {
      break;
    }
  }
  if (!inUse.count(curName)) {
    return curName;
  } else {
    goto st;
  }
}
vector<string> ans;
string dfs(long long pos, bool isRoot) {
  if (!node.count(pos)) {
    return hsh2var[pos];
  }
  if (name.count(pos)) {
    return name[pos];
  }
  string lp = dfs(node[pos].l, false);
  string rp = dfs(node[pos].r, false);
  string nm = (isRoot ? "res" : getName());
  ans.push_back(nm + "=" + lp + node[pos].op + rp);
  name[pos] = nm;
  return nm;
}
string readVar(string& s, int& po) {
  string ans = "";
  while (po < s.size()) {
    ans += s[po];
    po++;
    if (!isalpha(s[po]) && !isdigit(s[po])) {
      return ans;
    }
  }
  return ans;
}
long long mixHash(long long h1, long long h2, char op) {
  return h1 * 1000000007 + op * 998244353 + h2;
}
int main(int argc, char* argv[]) {
  ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> code[i];
  }
  for (int i = 0; i < n; i++) {
    int pointer = 0;
    string lv = readVar(code[i], pointer);
    pointer++;
    string rv = readVar(code[i], pointer);
    if (pointer == code[i].size()) {
      val[lv] = getVal(rv);
    } else {
      char op = code[i][pointer];
      pointer++;
      string rv2 = readVar(code[i], pointer);
      long long v1 = getVal(rv);
      long long v2 = getVal(rv2);
      val[lv] = mixHash(v1, v2, op);
      node[val[lv]] = Node(v1, v2, op);
    }
  }
  if (!val.count("res")) {
    cout << "0" << endl;
    return 0;
  }
  string omg = dfs(val["res"], true);
  if (omg != "res") {
    cout << "1" << endl;
    cout << "res=" << omg << endl;
    return 0;
  }
  cout << ans.size() << endl;
  for (string x : ans) {
    cout << x << endl;
  }
  return 0;
}
