#include <bits/stdc++.h>
using namespace std;
int IndexOf(string &s, string &sub) {
  int sLen = s.length();
  int subLen = sub.length();
  if (subLen > sLen) return -1;
  for (int i = 0; i <= sLen - subLen; i++) {
    if (s.substr(i, subLen) == sub) return i;
  }
  return -1;
}
int lastIndexOf(string &s, string &sub) {
  int sLen = s.length();
  int subLen = sub.length();
  if (subLen > sLen) return -1;
  for (int i = sLen - subLen; i >= 0; i--) {
    if (s.substr(i, subLen) == sub) return i;
  }
  return -1;
}
void reverseStr(string &s) {
  for (int i = 0, j = s.length() - 1; i < s.length() / 2; i++, j--) {
    char temp = s[i];
    s[i] = s[j];
    s[j] = temp;
  }
}
bool Check(string &flags, string &first, string &second) {
  int indexFirst = IndexOf(flags, first);
  int lastIndexSecond = lastIndexOf(flags, second);
  return (indexFirst != -1 && lastIndexSecond != -1 &&
          indexFirst + first.length() - 1 < lastIndexSecond);
}
int main() {
  string flags, first, second;
  cin >> flags >> first >> second;
  bool f = Check(flags, first, second);
  reverseStr(flags);
  bool b = Check(flags, first, second);
  if (f && b)
    cout << "both";
  else if (f)
    cout << "forward";
  else if (b)
    cout << "backward";
  else
    cout << "fantasy";
  return 0;
}
