#include <bits/stdc++.h>
using namespace std;
char a[100000 + 100];
char b[100000 + 100];
char c[100000 + 100];
int p1[100000 + 100];
int p2[100000 + 100];
int n, m, k;
void pre(char *s, int *p, int q) {
  for (int i = 1; i < q; i++) {
    int j = p[i - 1];
    while (j > 0 && s[i] != s[j]) j = p[j - 1];
    if (s[i] == s[j]) ++j;
    p[i] = j;
  }
}
set<int> ans;
int check() {
  int j = 0, k = 0;
  int first = -1;
  for (int i = 0; i < n; i++) {
    while (j > 0 && a[i] != b[j]) j = p1[j - 1];
    while (k > 0 && a[i] != c[k]) k = p2[k - 1];
    if (!(a[i] != b[j])) j++;
    if (!(a[i] != c[k])) k++;
    if (j == m) {
      if (first == -1) first = i;
      j = p1[j - 1];
    }
    if (k == ::k) {
      k = p2[k - 1];
      if (first == -1) continue;
      if ((i - ::k) >= first) return 1;
    }
  }
  return 0;
}
int main() {
  gets(a);
  gets(b);
  gets(c);
  n = strlen(a);
  m = strlen(b);
  k = strlen(c);
  pre(b, p1, m);
  pre(c, p2, k);
  int forward = check();
  reverse(a, a + strlen(a));
  int backward = check();
  int both = forward + backward;
  if (both == 0) {
    cout << "fantasy";
    return 0;
  }
  if (both == 2) {
    cout << "both";
    return 0;
  }
  if (forward) {
    cout << "forward";
    return 0;
  }
  cout << "backward";
  return 0;
}
