
// solution to problem Digital Friends
// Walter Kosters, 30 August 2006

#include <iostream>
using namespace std;

const int MAXLENGTH = 200;

// are x and y friends?
bool friends (int x[ ], int xlength, int y[ ], int ylength) {
  bool A[10];
  bool B[10];
  int i;
  for ( i = 0; i < 10; i++ ) A[i] = B[i] = false;
  for ( i = 0 ; i < xlength; i++ ) A[x[i]] = true;
  for ( i = 0 ; i < ylength; i++ ) B[y[i]] = true;
  for ( i = 0; i < 10; i++ ) 
    if ( A[i] != B[i] ) return false;
  return true;
}//friends

// are x and y almost friends through a neighbour change in x?
// much more efficient if you remember the digits of y
bool almostfriends (int x[ ], int xlength, int y[ ], int ylength) {
  int i;
  for ( i = 0; i < xlength-1; i++ ) {
    x[i]++; x[i+1]--;
    if ( x[i] <= 9 && x[i+1] >= 0 )
      if ( friends (x,xlength,y,ylength) ) return true;
    x[i]--; x[i+1]++;
    x[i]--; x[i+1]++;
    if ( x[i] >= 0 && x[i+1] <= 9 && ( i > 0 || x[i] > 0 ) )
      if ( friends (x,xlength,y,ylength) ) return true;
    x[i]++; x[i+1]--;
  }//for
  return false;
}//almostfriends

int main ( ) {
  int thecase, numberofcases;
  int x[MAXLENGTH];
  int y[MAXLENGTH];
  int xlength, ylength;
  char kar;
  cin >> numberofcases;
  for ( thecase = 0; thecase < numberofcases; thecase++ ) {
    xlength = ylength = 0;
    kar = cin.get ( );
    while ( ! ( '0' <= kar && kar <= '9' ) ) kar = cin.get ( );
    while ( '0' <= kar && kar <= '9' ) {
      x[xlength] = kar - '0';
      xlength++;
      kar = cin.get ( );
    }//while
    while ( ! ( '0' <= kar && kar <= '9' ) ) kar = cin.get ( );
    while ( '0' <= kar && kar <= '9' ) {
      y[ylength] = kar - '0';
      ylength++;
      kar = cin.get ( );
    }//while
    if ( friends (x,xlength,y,ylength) ) cout << "friends" << endl;
    else if ( almostfriends (x,xlength,y,ylength) 
           || almostfriends (y,ylength,x,xlength) ) cout << "almost friends" << endl;
    else cout << "nothing" << endl;
  }//for
  return 0;
}//main

