#include <bits/stdc++.h>
using namespace std;
char s[100010], a[110], b[110];
bool tu(char *S, char *A) {
  int x = strlen(A);
  for (int i = 0; i < x; ++i)
    if (S[i] != A[i]) return false;
  return true;
}
bool tuu(char *S, char *A) {
  int x = strlen(A);
  for (int i = 0; i < x; ++i)
    if (S[-i] != A[i]) return false;
  return true;
}
int main() {
  scanf("%s%s%s", s, a, b);
  bool o1 = false, o2 = false;
  int S = strlen(s), A = strlen(a), B = strlen(b);
  for (int i = 0; i + A <= S; ++i) {
    if (tu(s + i, a)) {
      for (i += A; i + B <= S; ++i) {
        if (tu(s + i, b)) o1 = true;
      }
    }
  }
  for (int i = S - 1; i - A >= -1; --i) {
    if (tuu(s + i, a)) {
      for (i -= A; i - B >= -1; --i) {
        if (tuu(s + i, b)) o2 = true;
      }
    }
  }
  if (o1 && o2)
    printf("both\n");
  else if (o1)
    printf("forward\n");
  else if (o2)
    printf("backward\n");
  else
    printf("fantasy\n");
  return 0;
}
