#include <bits/stdc++.h>
using namespace std;
int main() {
  string sh;
  cin >> sh;
  string a, b;
  cin >> a >> b;
  bool flg1 = 0, flg2 = 0;
  {
    int index_a = sh.find(a);
    if (index_a >= 0 && index_a + a.size() < sh.length()) {
      int index_b =
          sh.substr(index_a + a.size(), sh.length() - index_a - a.size())
              .find(b);
      if (index_b >= 0) flg1 = 1;
    }
  }
  reverse(sh.begin(), sh.end());
  {
    int index_a = sh.find(a);
    if (index_a >= 0 && index_a + a.size() < sh.length()) {
      int index_b =
          sh.substr(index_a + a.size(), sh.length() - index_a - a.size())
              .find(b);
      if (index_b >= 0) flg2 = 1;
    }
  }
  if (flg1 && flg2)
    puts("both");
  else if (flg1)
    puts("forward");
  else if (flg2)
    puts("backward");
  else
    puts("fantasy");
}
