#include <bits/stdc++.h>
using namespace std;
int main() {
  bool forward = false, backward = false;
  string flags, s1, s2, temp;
  cin >> flags >> s1 >> s2;
  temp = s1 + s2;
  size_t first = flags.find(s1);
  if (first != string::npos) {
    size_t second = flags.find(s2, first + s1.length());
    forward = second != string::npos;
  }
  reverse(flags.begin(), flags.end());
  first = flags.find(s1);
  if (first != string::npos) {
    size_t second = flags.find(s2, first + s1.length());
    backward = second != string::npos;
  }
  if (forward && backward)
    cout << "both";
  else if (forward)
    cout << "forward";
  else if (backward)
    cout << "backward";
  else
    cout << "fantasy";
}
