#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  string a, b, orig;
  bool fd = 0, bk = 0;
  cin >> orig >> a >> b;
  if (orig.find(a) != string::npos) {
    int pos = orig.find(a);
    if (orig.find(b, pos + a.length()) != string::npos) fd = 1;
  }
  reverse(orig.begin(), orig.end());
  if (orig.find(a) != string::npos) {
    int pos = orig.find(a);
    if (orig.find(b, pos + a.length()) != string::npos) bk = 1;
  }
  if (fd and bk)
    cout << "both";
  else if (fd)
    cout << "forward";
  else if (bk)
    cout << "backward";
  else
    cout << "fantasy";
  return 0;
}
