#include <bits/stdc++.h>
std::string reverse(std::string s) {
  std::string reversed = "";
  for (int i = s.length() - 1; i >= 0; --i) {
    reversed.push_back(s.at(i));
  }
  return reversed;
}
bool foundInTrip(std::string first, std::string second, std::string trip) {
  std::size_t found_1_forward = trip.find(first);
  std::size_t found_2_forward = trip.rfind(second);
  return (found_1_forward != std::string::npos &&
          found_2_forward != std::string::npos &&
          found_2_forward >= found_1_forward + first.length());
}
int main() {
  std::string trip;
  std::cin >> trip;
  std::string one;
  std::string two;
  std::cin >> one >> two;
  bool forwardWorks = foundInTrip(one, two, trip);
  trip = reverse(trip);
  bool backwardWorks = foundInTrip(one, two, trip);
  if (forwardWorks && backwardWorks) {
    std::cout << "both" << std::endl;
  } else if (forwardWorks) {
    std::cout << "forward" << std::endl;
  } else if (backwardWorks) {
    std::cout << "backward" << std::endl;
  } else {
    std::cout << "fantasy" << std::endl;
  }
}
