#include <bits/stdc++.h>
using namespace std;
int find(const string& flags, const string& first, const string& second) {
  auto it = flags.find(first);
  if (it == string::npos) return false;
  it = flags.find(second, it + first.size());
  return it != string::npos;
}
int main() {
  ios::sync_with_stdio(false);
  string flags, first, second;
  cin >> flags >> first >> second;
  int ways = find(flags, first, second);
  reverse(flags.begin(), flags.end());
  ways += find(flags, first, second) << 1;
  switch (ways) {
    case 0:
      cout << "fantasy\n";
      break;
    case 1:
      cout << "forward\n";
      break;
    case 2:
      cout << "backward\n";
      break;
    case 3:
      cout << "both\n";
      break;
  }
  return 0;
}
