#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
string s1 = "", s2 = "";
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s, a, b;
  cin >> s >> a >> b;
  bool ans1 = false, ans2 = false;
  int p = (int)s.find(a), q = 0;
  if (p >= 0 && p < (int)s.size()) {
    s1.insert(s1.begin(), s.begin() + p + a.size(), s.end());
    q = (int)s1.find(b);
    if (q >= 0 && q < (int)s.size()) ans1 = true;
  }
  reverse(s.begin(), s.end());
  p = (int)s.find(a);
  q = 0;
  if (p >= 0 && p < (int)s.size()) {
    s2.insert(s2.begin(), s.begin() + p + a.size(), s.end());
    q = (int)s2.find(b);
    if (q >= 0 && q < (int)s.size()) ans2 = true;
  }
  if (ans1 && ans2)
    cout << "both" << endl;
  else {
    if (!ans1 && !ans2)
      cout << "fantasy" << endl;
    else {
      if (ans1)
        cout << "forward" << endl;
      else
        cout << "backward" << endl;
    }
  }
  return 0;
}
