#include <bits/stdc++.h>
using namespace std;
int main() {
  string stations, sq1, sq2;
  cin >> stations >> sq1 >> sq2;
  size_t p1, p2;
  bool forward = false, backward = false;
  p1 = stations.find(sq1);
  if (p1 != string::npos) {
    p2 = stations.find(sq2, p1 + sq1.length());
    forward = p2 != string::npos;
  }
  reverse(stations.begin(), stations.end());
  p1 = stations.find(sq1);
  if (p1 != string::npos) {
    p2 = stations.find(sq2, p1 + sq1.length());
    backward = p2 != string::npos;
  }
  if (forward && backward)
    cout << "both" << endl;
  else if (forward && !backward)
    cout << "forward" << endl;
  else if (!forward && backward)
    cout << "backward" << endl;
  else
    cout << "fantasy" << endl;
  return 0;
}
