#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 9;
char d[maxn];
string a;
string b;
string c;
int main() {
  cin >> a >> b >> c;
  int A, B, C;
  int flag = 0;
  int flag1 = 0;
  int flag2 = 0;
  int i, j;
  int len;
  size_t repos1;
  size_t repos2;
  repos1 = a.find(b);
  repos2 = a.find(c, repos1 + b.length());
  if (repos1 != string::npos && repos2 != string::npos) flag1 = 1;
  len = a.length() - 1;
  j = len;
  i = 0;
  for (; i < j; i++, j--) {
    char t;
    t = a[i];
    a[i] = a[j];
    a[j] = t;
  }
  size_t popos1;
  size_t popos2;
  popos1 = a.find(b);
  popos2 = a.find(c, popos1 + b.length());
  if (popos2 != string::npos && popos1 != string::npos) flag2 = 1;
  if (flag1 == 1) {
    if (flag2 == 1)
      cout << "both\n";
    else
      cout << "forward\n";
  } else {
    if (flag2 == 1)
      cout << "backward\n";
    else
      cout << "fantasy\n";
  }
  return 0;
}
