#include <bits/stdc++.h>
using namespace std;
int N, T, M, K;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string a, b, c;
  cin >> a >> b >> c;
  int x = 0, y = 0;
  if (a.find(b) < 100005)
    if (a.find(c, a.find(b) + (int)b.size()) < 100005) x = 1;
  reverse(a.begin(), a.end());
  if (a.find(b) < 100005)
    if (a.find(c, a.find(b) + (int)b.size()) < 100005) y = 1;
  if (x && y)
    cout << "both\n";
  else if (x && !y)
    cout << "forward\n";
  else if (!x && y)
    cout << "backward\n";
  else
    cout << "fantasy\n";
  return 0;
}
