#include <bits/stdc++.h>
using namespace std;
char s[100005], a[2][105];
int lens, len[2];
bool test(int now, int st, int d) {
  int i, j;
  if (d == 1 && st + len[now] - 1 >= lens) return false;
  if (d == -1 && st - len[now] + 1 < 0) return false;
  for (i = st, j = 0; j < len[now]; j++, i += d)
    if (s[i] != a[now][j]) return false;
  return true;
}
int main() {
  int i, j, k;
  while (gets(s)) {
    gets(a[0]);
    gets(a[1]);
    lens = strlen(s);
    len[0] = strlen(a[0]);
    len[1] = strlen(a[1]);
    int ans = 0, now = 0;
    for (i = 0; i < lens; i++) {
      if (test(now, i, 1)) {
        i += len[now];
        i--;
        now++;
      }
      if (now == 2) {
        ans += 1;
        break;
      }
    }
    now = 0;
    for (i = lens - 1; i >= 0; i--) {
      if (test(now, i, -1)) {
        i -= len[now];
        i++;
        now++;
      }
      if (now == 2) {
        ans += 2;
        break;
      }
    }
    if (ans == 0)
      printf("fantasy\n");
    else if (ans == 1)
      printf("forward\n");
    else if (ans == 2)
      printf("backward\n");
    else
      printf("both\n");
  }
  return 0;
}
