#include <bits/stdc++.h>
using namespace std;
string rev(string a) {
  int i;
  string b;
  for (i = a.length() - 1; i >= 0; i--) {
    b += a[i];
  }
  return b;
}
int main() {
  string a, b, c, re;
  int flag = 0, i, j, temp = 0, temp2 = 0, flag2 = 0, k = 0;
  cin >> a;
  cin >> b;
  cin >> c;
  re = rev(a);
  std::size_t found = a.find(b);
  if (found != std::string::npos) {
    found = a.find(c, found + b.size());
    flag = 1;
  }
  if (found != string::npos && flag) {
    flag = 2;
  }
  found = re.find(b);
  if (found != std::string::npos) {
    found = re.find(c, found + b.size());
    flag2 = 1;
  }
  if (found != std::string::npos && flag2 == 1) {
    flag2 = 2;
  }
  if (flag == 2 && flag2 == 2) {
    cout << "both" << endl;
  } else if (flag == 2 && flag2 != 2) {
    cout << "forward" << endl;
  } else if (flag != 2 && flag2 == 2) {
    cout << "backward" << endl;
  } else {
    cout << "fantasy" << endl;
  }
}
