#include <bits/stdc++.h>
using namespace std;
string Be(string s1, string s2, string s3) {
  int j = s1.find(s2), k;
  string s = s1, OK, s2n = s2, s3n = s3;
  if (j != -1) {
    for (int i = j; i < s2.size() + j; i++) s1[i] = '0';
    k = s1.rfind(s3);
    if (k != -1) {
      if (k > j) OK += "F";
    }
  }
  s1 = s;
  s2 = string(s2.rbegin(), s2.rend());
  j = s1.rfind(s2);
  if (j != -1) {
    for (int i = j; i < s2.size() + j; i++) s1[i] = '0';
  }
  s3 = string(s3.rbegin(), s3.rend());
  k = s1.find(s3);
  if (k != -1 && j != -1) {
    if (k < j) OK += "B";
  }
  return OK;
}
int main() {
  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;
  if (Be(s1, s2, s3) == "B")
    cout << "backward";
  else if (Be(s1, s2, s3) == "F")
    cout << "forward";
  else if (Be(s1, s2, s3) == "FB")
    cout << "both";
  else
    cout << "fantasy";
}
