#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, s1, s2;
  getline(cin, s);
  getline(cin, s1);
  getline(cin, s2);
  int substr = s.find(s1), substr1;
  int forward = 0, backward = 0;
  if (substr != -1) {
    substr1 = s.find(s2, substr + s1.length());
    if (substr1 != -1) forward = 1;
  }
  string inverted;
  for (substr = 0; substr <= s.length() - 1; substr++)
    inverted = s[substr] + inverted;
  substr = inverted.find(s1);
  if (substr != -1) {
    substr1 = inverted.find(s2, substr + s1.length());
    if (substr1 != -1) backward = 1;
  }
  if (forward == 1 && backward == 0) cout << "forward" << endl;
  if (forward == 0 && backward == 1) cout << "backward" << endl;
  if (forward == 1 && backward == 1) cout << "both" << endl;
  if (forward == 0 && backward == 0) cout << "fantasy" << endl;
  return 0;
}
