#include <bits/stdc++.h>
const int N = 100000 + 5;
int Next[N], lens, lena, lenb;
char a[N], b[N], s[N];
bool forward, backward;
void getnext(char *s) {
  int lens = strlen(s);
  int i = 0, t = -1;
  Next[i] = -1;
  while (i < lens) {
    if (t == -1 || s[i] == s[t]) {
      ++i;
      ++t;
      Next[i] = t;
    } else
      t = Next[t];
  }
}
bool kmp() {
  bool ok1 = false, ok2 = false;
  getnext(a);
  int i = 0, j = 0;
  while (i < lens) {
    if (j == -1 || s[i] == a[j]) {
      ++i;
      ++j;
      if (j == lena) {
        ok1 = true;
        break;
      }
    } else
      j = Next[j];
  }
  if (!ok1) return false;
  getnext(b);
  j = 0;
  while (i < lens) {
    if (j == -1 || s[i] == b[j]) {
      ++i;
      ++j;
      if (j == lenb) {
        ok2 = true;
        break;
      }
    } else
      j = Next[j];
  }
  if (!ok2) return false;
  return true;
}
int main() {
  scanf("%s%s%s", s, a, b);
  lens = strlen(s);
  lena = strlen(a);
  lenb = strlen(b);
  forward = kmp();
  for (int i = 0; i < lens / 2; ++i) {
    char t = s[i];
    s[i] = s[lens - i - 1];
    s[lens - i - 1] = t;
  }
  backward = kmp();
  if (forward && backward)
    puts("both");
  else if (!forward && !backward)
    puts("fantasy");
  else if (!forward && backward)
    puts("backward");
  else
    puts("forward");
  return 0;
}
