#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
bool lookfor(string str, string s1, string s2) {
  size_t k = str.find(s1);
  if (k == string::npos) return false;
  size_t h = str.find(s2, k + (long long)s1.size());
  if (h == string::npos) return false;
  return true;
}
int main() {
  string str;
  string s1, s2;
  cin >> str;
  cin >> s1;
  cin >> s2;
  bool b1 = lookfor(str, s1, s2);
  reverse(str.begin(), str.end());
  bool b2 = lookfor(str, s1, s2);
  string ans;
  if (b1 && b2)
    ans = "both";
  else if (b1)
    ans = "forward";
  else if (b2)
    ans = "backward";
  else
    ans = "fantasy";
  cout << ans << endl;
  return 0;
}
