#include <bits/stdc++.h>
using namespace std;
string s;
string a, b;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> s;
  cin >> a >> b;
  size_t f = 0;
  if (a.size() <= s.size()) {
    f = s.find(a);
    if (f < s.size()) {
      if (b.size() <= s.size() - f + a.size() + 1)
        if (s.find(b, f + a.size()) < s.size()) {
          f = 1;
        } else
          f = 0;
      else
        f = 0;
    } else {
      f = 0;
    }
  }
  size_t q = 0;
  reverse(s.begin(), s.end());
  if (a.size() <= s.size()) {
    q = s.find(a);
    if (q < s.size()) {
      if (b.size() <= s.size() - q + a.size() + 1)
        if (s.find(b, q + a.size()) < s.size()) {
          q = 1;
        } else
          q = 0;
      else
        q = 0;
    } else {
      q = 0;
    }
  }
  if (f and q)
    cout << "both\n";
  else if (f)
    cout << "forward\n";
  else if (q)
    cout << "backward\n";
  else
    cout << "fantasy\n";
  return 0;
}
