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 JAVA):

Solution:
import java.io.*;
import java.util.*;

public class CF1156G {
	static Random rand = new Random();
	static HashSet<String> ss = new HashSet<>();
	static class V {
		String s;
		char op;
		V u, v;
		int code = rand.nextInt();
		int d;
		V(String s) {
			this.s = s;
			ss.add(s);
		}
		V(char op, V u, V v) {
			this.op = op; this.u = u; this.v = v;
			d = Math.max(u.d, v.d) + 1;
		}
		@Override
		public String toString() {
			return s + "=" + u.s + op + v.s;
		}
		@Override
		public boolean equals(Object o) {
			V w = (V) o;
			return op == w.op && u == w.u && v == w.v;
		}
		@Override
		public int hashCode() {
			return op ^ u.code ^ v.code;
		}
	}
	static ArrayList<V> list = new ArrayList<>();
	static String getX() {
		String s;
		do {
			char a = (char) ('a' + rand.nextInt(26));
			char b = (char) ('a' + rand.nextInt(26));
			char c = (char) ('a' + rand.nextInt(26));
			char d = (char) ('a' + rand.nextInt(26));
			s = "" + a + b + c + d;
		} while (ss.contains(s));
		return s;
	}
	static void dfs(V w, String s) {
		if (w.s == null) {
			w.s = s;
			ss.add(s);
			list.add(w);
			dfs(w.u, getX());
			dfs(w.v, getX());
		}
	}
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		HashMap<String, V> sv = new HashMap<>();
		HashMap<V, V> vv = new HashMap<>();
		while (n-- > 0) {
			char[] cc = br.readLine().toCharArray();
			int m = cc.length;
			int p = -1, q = -1;
			for (int j = 0; j < m; j++)
				if (cc[j] == '=')
					p = j;
				else if (cc[j] == '$' || cc[j] == '^' || cc[j] == '#' || cc[j] == '&')
					q = j;
			String lvalue = new String(cc, 0, p);
			if (q == -1) {
				String rvalue = new String(cc, p + 1, m - p - 1);
				V v = sv.get(rvalue);
				if (v == null) {
					v = new V(rvalue);
					sv.put(rvalue, v);
				}
				sv.put(lvalue, v);
			} else {
				String arg1 = new String(cc, p + 1, q - p - 1);
				String arg2 = new String(cc, q + 1, m - q - 1);
				char op = cc[q];
				V u = sv.get(arg1);
				if (u == null) {
					u = new V(arg1);
					sv.put(arg1, u);
				}
				V v = sv.get(arg2);
				if (v == null) {
					v = new V(arg2);
					sv.put(arg2, v);
				}
				V w = new V(op, u, v);
				V w_ = vv.get(w);
				if (w_ == null) {
					w_ = w;
					vv.put(w, w);
				}
				sv.put(lvalue, w_);
			}
		}
		V w = sv.get("res");
		if (w == null) {
			System.out.println(0);
			return;
		}
		if (w.op == 0) {
			if (w.s.equals("res"))
				System.out.println(0);
			else {
				System.out.println(1);
				System.out.println("res=" + w.s);
			}
			return;
		}
		dfs(w, "res");
		Collections.sort(list, (u, v) -> u.d - v.d);
		PrintWriter pw = new PrintWriter(System.out);
		pw.println(list.size());
		for (V v : list)
			pw.println(v);
		pw.close();
	}
}