#include <bits/stdc++.h>
using namespace std;
string s;
string a, b;
int main() {
  cin >> s >> a >> b;
  size_t fa = s.find(a);
  size_t fb = s.rfind(b);
  bool forward = false;
  if (fa != string::npos && fb != string::npos && fb > fa &&
      fa + a.length() <= fb)
    forward = true;
  reverse(s.begin(), s.end());
  size_t ba = s.find(a);
  size_t bb = s.rfind(b);
  bool backward = false;
  if (ba != string::npos && bb != string::npos && bb > ba &&
      ba + a.length() <= bb)
    backward = true;
  if (forward && backward)
    cout << "both";
  else if (forward)
    cout << "forward";
  else if (backward)
    cout << "backward";
  else
    cout << "fantasy";
  return 0;
}
