#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, s1, s2;
  cin >> s >> s1 >> s2;
  bool f = 0, b = 0;
  if (s1.size() + s2.size() > s.size()) {
    cout << "fantasy";
    return 0;
  }
  for (int i = 0; i < s.size() - s1.size() - s2.size() + 1; i++) {
    if (s.substr(i, s1.size()) == s1) {
      for (int j = i + 1; j < s.size() - s2.size() + 1; j++)
        if (s.substr(j, s2.size()) == s2) {
          f = 1;
          break;
        }
    }
    if (f) break;
  }
  reverse(s.begin(), s.end());
  for (int i = 0; i < s.size() - s1.size() - s2.size() + 1; i++) {
    if (s.substr(i, s1.size()) == s1) {
      for (int j = i + 1; j < s.size() - s2.size() + 1; j++)
        if (s.substr(j, s2.size()) == s2) {
          b = 1;
          break;
        }
    }
    if (b) break;
  }
  (f && b)    ? cout << "both"
  : (!f && b) ? cout << "backward"
  : (f && !b) ? cout << "forward"
              : cout << "fantasy";
}
