#include <bits/stdc++.h>
using namespace std;
void c_p_c() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
long long me(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
int main() {
  c_p_c();
  string s;
  string s1;
  string s2;
  cin >> s >> s1 >> s2;
  long long n1 = s1.length();
  long long n2 = s2.length();
  long long f = 0;
  long long b = 0;
  size_t found = s.find(s1);
  if (found != string::npos) {
    size_t found1 = s.find(s2, found + n1);
    if (found1 != string::npos) f++;
  }
  reverse(s.begin(), s.end());
  size_t found3 = s.find(s1);
  if (found3 != string::npos) {
    size_t found4 = s.find(s2, found3 + n1);
    if (found4 != string::npos) b++;
  }
  if (f == 1 && b == 1)
    cout << "both";
  else if (f == 1)
    cout << "forward";
  else if (b == 1)
    cout << "backward";
  else
    cout << "fantasy";
  return 0;
}
