#include <bits/stdc++.h>
using namespace std;
int main() {
  string n, a, b;
  bool forw = false, backw = false;
  cin >> n >> a >> b;
  if (n.find(a) != -1 && n.find(b, a.size() + n.find(a)) != -1) forw = true;
  reverse(n.begin(), n.end());
  if (n.find(a) != -1 && n.find(b, n.find(a) + a.size()) != -1) backw = true;
  if (forw && backw)
    cout << "both";
  else if (forw)
    cout << "forward";
  else if (backw)
    cout << "backward";
  else
    cout << "fantasy";
  return 0;
}
