// BAPC06 Digital Friends, Marijn Kruisselbrink
import java.util.*;
       class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] arg) {
		int n = sc.nextInt(); while (n-- > 0) new Main().solve();
	}

	static int[] count(char[] n) {
		int[] res = new int[10];
		for (int i = 0; i < n.length; i++) res[n[i]]++;
		return res;
	}
	
	boolean friends(int[] xc, int[] yc) {
		for (int i = 0; i < 10; i++) {
			if ((xc[i] > 0) != (yc[i] > 0)) return false;
		}
		return true;
	}
	
	char[] conv(char[] c) {
		for (int i = 0; i < c.length; i++) c[i] -= '0';
		return c;
	}
	void solve() {
		char[] x = conv(sc.next().toCharArray());
		char[] y = conv(sc.next().toCharArray());
		int[] xc = count(x);
		int[] yc = count(y);
		if (friends(xc, yc)) {
			System.out.println("friends");
		} else if (test(x, xc, y, yc) || test(y, yc, x ,xc)) {
			System.out.println("almost friends");
		} else {	
			System.out.println("nothing");
		}
	}

	boolean test(char[] x, int[] xc, char[] y, int[] yc) {
		for (int i = 0; i < x.length-1; i++) {
			if (x[i] > (i == 0 ? 1 : 0) && x[i+1] < 9) {
				xc[x[i]]--; xc[x[i]-1]++;
				xc[x[i+1]]--; xc[x[i+1]+1]++;
				if (friends(xc, yc)) return true;
				xc[x[i+1]]++; xc[x[i+1]+1]--;
				xc[x[i]]++; xc[x[i]-1]--;
			}
			if (x[i] < 9 && x[i+1] > 0) {
				xc[x[i]]--; xc[x[i]+1]++;
				xc[x[i+1]]--; xc[x[i+1]-1]++;
				if (friends(xc, yc)) return true;
				xc[x[i+1]]++; xc[x[i+1]-1]--;
				xc[x[i]]++; xc[x[i]+1]--;
			}
		}
		return false;
	}
}

