#include <bits/stdc++.h>
using namespace std;
const int MX = 100009;
char pat[MX];
char str[MX];
int ind[MX];
int ff[MX];
int KMP() {
  int k = 0;
  ff[0] = 0;
  int patn = strlen(pat);
  int strn = strlen(str);
  for (int i = 1; i < patn; i++) {
    while (k > 0 && pat[i] != pat[k]) k = ff[k - 1];
    if (pat[i] == pat[k]) k++;
    ff[i] = k;
  }
  k = 0;
  int ret = 0;
  for (int i = 0; i < strn; i++) {
    while (k > 0 && pat[k] != str[i]) k = ff[k - 1];
    if (pat[k] == str[i]) k++;
    if (k == patn) {
      ind[ret++] = i - patn + 1;
      k = ff[k - 1];
    }
  }
  return ret;
}
string s1;
int solve(string &s, int ind2) {
  for (int i = ind2; i < (int)s1.size(); i++) str[i - ind2] = s1[i];
  str[s1.size() - ind2] = '\0';
  for (int i = 0; i < (int)s.size(); i++) pat[i] = s[i];
  pat[s.size()] = '\0';
  int n = KMP();
  if (!n) return -1;
  return ind[0];
}
int main() {
  string s2, s3;
  cin >> s1 >> s2 >> s3;
  bool f = 0;
  int x = solve(s2, 0);
  if (x != -1) {
    x = solve(s3, x + s2.size());
    if (x != -1) f = 1;
  }
  reverse(s1.begin(), s1.end());
  bool b = 0;
  x = solve(s2, 0);
  if (x != -1) {
    x = solve(s3, x + s2.size());
    if (x != -1) b = 1;
  }
  if (f && b)
    cout << "both" << endl;
  else if (f)
    cout << "forward" << endl;
  else if (b)
    cout << "backward" << endl;
  else
    cout << "fantasy" << endl;
  return 0;
}
