#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  string a, b, c;
  cin >> a >> b >> c;
  bool right = false, left = false;
  if (a.find(b) != string::npos) {
    if (a.find(c, (int)a.find(b) + (int)b.size()) != string::npos) {
      right = true;
    }
  }
  reverse(a.begin(), a.end());
  if (a.find(b) != string::npos) {
    if (a.find(c, (int)a.find(b) + (int)b.size()) != string::npos) {
      left = true;
    }
  }
  cout << (right ? (left ? "both" : "forward")
                 : (left ? "backward" : "fantasy"));
  return 0;
}
