#include <bits/stdc++.h>
using namespace std;
long long h1[100009], h2[100009], p[100009];
int i, j, n;
string s, a, b, ans[4] = {"fantasy", "forward", "backward", "both"};
int main() {
  cin >> s >> a >> b;
  if ((i = s.find(a)) != -1 && s.find(b, a.size() + i) != -1) n++;
  reverse(s.begin(), s.end());
  if ((i = s.find(a)) != -1 && s.find(b, a.size() + i) != -1) n += 2;
  cout << ans[n];
}
