#include <bits/stdc++.h>
using namespace std;
int diri[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dirj[] = {0, 1, 0, -1, 1, 1, -1, -1};
int compare(double d1, double d2) {
  if (fabs(d1 - d2) < 1e-9) return 0;
  if (d1 < d2) return -1;
  return 1;
}
char s[100500], a[101], b[101];
int main() {
  cin >> s >> a >> b;
  int x = strlen(a), n = strlen(s);
  int flag = 0;
  if (strstr(s, a) && strstr(strstr(s, a) + x, b)) flag |= 1;
  reverse(s, s + n);
  if (strstr(s, a) && strstr(strstr(s, a) + x, b)) flag |= 2;
  string ans[] = {"fantasy", "forward", "backward", "both"};
  cout << ans[flag] << endl;
  return 0;
}
