#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, x, y, m;
  int i, c, j, k, d;
  while (cin >> s >> x >> y) {
    k = 10;
    for (i = 0; i <= s.size() - x.size(); i++) {
      if (s[i] == x[0]) {
        k = 0;
        for (j = 1; j <= (x.size() - 1); j++) {
          if (x[j] != s[i + j]) {
            k = 1;
            break;
          }
        }
      }
      if (k == 0) break;
    }
    if (k == 0) {
      c = i + x.size();
      for (i = c; i <= s.size() - y.size(); i++) {
        if (s[i] == y[0]) {
          k = 3;
          for (j = 1; j <= (y.size() - 1); j++) {
            if (y[j] != s[i + j]) {
              k = 2;
              break;
            }
          }
        }
        if (k == 3) break;
      }
    }
    reverse(s.begin(), s.end());
    d = 10;
    for (i = 0; i <= s.size() - x.size(); i++) {
      if (s[i] == x[0]) {
        d = 0;
        for (j = 1; j <= (x.size() - 1); j++) {
          if (x[j] != s[i + j]) {
            d = 1;
            break;
          }
        }
      }
      if (d == 0) break;
    }
    if (d == 0) {
      c = i + x.size();
      for (i = c; i <= s.size() - y.size(); i++) {
        if (s[i] == y[0]) {
          d = 3;
          for (j = 1; j <= (y.size() - 1); j++) {
            if (y[j] != s[i + j]) {
              d = 2;
              break;
            }
          }
        }
        if (d == 3) break;
      }
    }
    if (x.size() >= s.size() or y.size() >= s.size()) {
      k = 10;
      d = 10;
    }
    if (k == 3 and d == 3)
      cout << "both" << endl;
    else if (k == 3)
      cout << "forward" << endl;
    else if (d == 3)
      cout << "backward" << endl;
    else
      cout << "fantasy" << endl;
  }
  return 0;
}
