#include <bits/stdc++.h>
using namespace std;
void revString(string *road) {
  for (int i = 0, j = (*road).size() - 1; i < (*road).size() / 2; i++, j--) {
    char temp = (*road)[i];
    (*road)[i] = (*road)[j];
    (*road)[j] = temp;
  }
}
int findIndexOf(string *source, string *substr1) {
  for (int i = 0; i <= (int)(*source).size() - (int)(*substr1).size(); i++)
    if ((*source).substr(i, (*substr1).size()) == (*substr1)) return i;
  return -1;
}
int findLastIndexOf(string *source, string *substr1) {
  for (int i = (*source).size() - (*substr1).size(); i >= 0; i--)
    if ((*source).substr(i, (*substr1).size()) == (*substr1)) return i;
  return -1;
}
int main() {
  string road;
  cin >> road;
  string firstawakness;
  string secondawakness;
  cin >> firstawakness;
  cin >> secondawakness;
  bool forwards = false;
  bool backwards = false;
  if (findIndexOf(&road, &firstawakness) != -1 &&
      findIndexOf(&road, &secondawakness) != -1) {
    if (findIndexOf(&road, &firstawakness) + firstawakness.size() - 1 <
        findLastIndexOf(&road, &secondawakness))
      forwards = true;
  }
  revString(&road);
  if (findIndexOf(&road, &firstawakness) != -1 &&
      findIndexOf(&road, &secondawakness) != -1) {
    if (findIndexOf(&road, &firstawakness) + firstawakness.size() - 1 <
        findLastIndexOf(&road, &secondawakness))
      backwards = true;
  }
  if (forwards && backwards)
    cout << "both";
  else if (!forwards && !backwards)
    cout << "fantasy";
  else
    forwards ? cout << "forward" : cout << "backward";
  return 0;
}
