#include <bits/stdc++.h>
using namespace std;
ifstream in("girdi.in");
string strr, str, str1, str2;
char *p1, *p2;
bool f, b;
int sayac, i;
int main() {
  cin >> strr >> str1 >> str2;
  str = strr;
  p1 = search(&str[0], &str[str.size()], &str1[0], &str1[str1.size()]);
  if (p1 != &str[str.size()]) {
    for (i = p1 - &str[0]; i < p1 - &str[0] + str1.size(); i++) str[i] = '*';
    p2 = search(p1, &str[str.size()], &str2[0], &str2[str2.size()]);
    if (p2 != &str[str.size()]) f = 1;
  }
  str = strr;
  reverse(&str[0], &str[str.size()]);
  p1 = search(&str[0], &str[str.size()], &str1[0], &str1[str1.size()]);
  if (p1 != &str[str.size()]) {
    for (i = p1 - &str[0]; i < p1 - &str[0] + str1.size(); i++) str[i] = '*';
    p2 = search(p1, &str[str.size()], &str2[0], &str2[str2.size()]);
    if (p2 != &str[str.size()]) b = 1;
  }
  if (f == 1 && b == 0) cout << "forward";
  if (f == 0 && b == 1) cout << "backward";
  if (f == 1 && b == 1) cout << "both";
  if (f == 0 && b == 0) cout << "fantasy";
  return 0;
}
