#include <bits/stdc++.h>
using namespace std;
long long GCD(long long a, long long b) {
  if (b == 0) return a;
  return GCD(b, a % b);
}
long long LCM(long long a, long long b) {
  long long gcd = GCD(a, b);
  return (a * b) / gcd;
}
int main() {
  long long i, j = 0, k = 0, n = 0, m = 0, t, x = 0, y = 0, z, s = 0, l;
  string a, b, c, d;
  cin >> a >> b >> c;
  x = a.size();
  y = b.size();
  z = c.size();
  for (i = 0; i < x - y - z + 1; i++) {
    d = a.substr(i, y);
    if (b == d) {
      n++;
      break;
    }
  }
  if (n > 0) {
    for (i = i + 1; i < x - z + 1; i++) {
      d = a.substr(i, z);
      if (c == d) {
        m++;
        break;
      }
    }
  }
  for (i = x - 1; i >= y + z - 1; i--) {
    d = a.substr(i - y + 1, y);
    reverse(d.begin(), d.end());
    if (b == d) {
      j++;
      break;
    }
  }
  if (j > 0) {
    for (i = i - 1; i >= z - 1; i--) {
      d = a.substr(i - z + 1, z);
      reverse(d.begin(), d.end());
      if (c == d) {
        k++;
        break;
      }
    }
  }
  if ((m + n) == 2 && (j + k) == 2)
    cout << "both";
  else if ((m + n) == 2)
    cout << "forward";
  else if ((j + k) == 2)
    cout << "backward";
  else {
    cout << "fantasy";
  }
}
