#include <bits/stdc++.h>
using namespace std;
string ans[4] = {"fantasy", "forward", "backward", "both"};
bool fs, ss;
bool solve(string a, string b, string c) {
  fs = false, ss = false;
  int fPos = a.find(b);
  if (fPos != -1 and (fPos + (int)b.size()) < (int)a.size()) {
    fPos = a.find(c, (fPos + (int)b.size()));
    if (fPos != -1) {
      return true;
    }
  }
  return false;
}
int main() {
  string a, b, c;
  while (cin >> a >> b >> c) {
    int F = solve(a, b, c);
    reverse(a.begin(), a.end());
    int B = solve(a, b, c);
    if (F and B)
      cout << "both" << endl;
    else if (F)
      cout << "forward" << endl;
    else if (B)
      cout << "backward" << endl;
    else
      cout << "fantasy" << endl;
  }
  return 0;
}
