#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<long long> v;
  map<string, int> n;
  long long c, d = 0, e = 0, i, f = 0, g = 0, j, k = 1, l = 0, r = 1, z, m, h,
               p[101];
  string y[4] = {"fantasy", "forward", "backward", "both"}, t, s, x, a, b;
  double q, u;
  cin >> s >> a >> b;
  if (s.find(a) != -1 && s.find(b, a.size() + s.find(a)) != -1) {
    d = d + 1;
  }
  reverse(s.begin(), s.end());
  if (s.find(a) != -1 && s.find(b, a.size() + s.find(a)) != -1) {
    d = d + 2;
  }
  cout << y[d];
}
