#include <bits/stdc++.h>
using namespace std;
int main() {
  string a, b, c;
  cin >> a >> b >> c;
  bool f1 = false, f2 = false, r1 = false, r2 = false;
  size_t p1 = a.find(b);
  if (p1 != string ::npos) f1 = true;
  size_t p2 = a.find(c, p1 + b.size());
  if (p2 != string ::npos) f2 = true;
  reverse(a.begin(), a.end());
  p1 = a.find(b);
  if (p1 != string ::npos) r1 = true;
  p2 = a.find(c, p1 + b.size());
  if (p2 != string ::npos) r2 = true;
  if (f1 && f2 && r1 && r2)
    cout << "both\n";
  else if (f1 && f2 && (!r1 || !r2))
    cout << "forward";
  else if ((!f1 || !f2) && r1 && r2)
    cout << "backward";
  else if ((!f1 || !f2) && (!r1 || !r2))
    cout << "fantasy\n";
  return 0;
}
