#include <bits/stdc++.h>
using namespace std;
const long long base = 1e9 + 7;
const long Max = 1e5 + 8;
string s, a, b;
int m, n;
bool check(const string& t) {
  size_t p = t.find(a);
  if (p == string::npos) return false;
  if (t.find(b, p + a.length()) == string::npos) return false;
  return true;
}
int main() {
  ios::sync_with_stdio(false);
  int x = 0, y = 0;
  cin >> s;
  m = s.length();
  cin >> a >> b;
  string v;
  v.assign(s);
  for (int i = 0; i < m; i++) v[i] = s[m - i - 1];
  x = check(s);
  y = check(v);
  if (x == 1 and y == 0) cout << "forward";
  if (x == 0 and y == 1) cout << "backward";
  if (x == 1 and y == 1) cout << "both";
  if (x == 0 and y == 0) cout << "fantasy";
}
