#include <bits/stdc++.h>
using namespace std;
const int INF = 1e5 + 5;
char a[INF], b[5][INF], c[INF];
int sum, len;
bool check(int x, int &y) {
  int len1 = strlen(b[x]), i = 0, j = 0;
  for (i = y, j = 0; j < len1; i++, j++) {
    if (i >= len) return false;
    if (b[x][j] != a[i]) return false;
  }
  y = i - 1;
  return true;
}
bool check1(int x, int &y) {
  int len1 = strlen(b[x]), i = 0, j = 0;
  for (i = y, j = 0; j < len1; j++, i--) {
    if (i < 0) return false;
    if (b[x][j] != a[i]) return false;
  }
  y = i + 1;
  return true;
}
signed main() {
  scanf("%s %s %s", a, b[0], b[1]);
  len = strlen(a);
  int cnt = 0;
  for (int i = 0; i < len; i++) {
    if (b[cnt][0] == a[i])
      if (check(cnt, i)) cnt++;
    if (cnt > 1) break;
  }
  if (cnt > 1) sum = 1;
  cnt = 0;
  for (int i = 0; i < len; i++) c[i] = a[i];
  for (int i = 0; i < len; i++) a[len - i - 1] = c[i];
  for (int i = 0; i < len; i++) {
    if (b[cnt][0] == a[i])
      if (check(cnt, i)) cnt++;
    if (cnt > 1) break;
  }
  if (cnt > 1) {
    if (sum)
      cout << "both\n";
    else
      cout << "backward\n";
  } else {
    if (sum)
      cout << "forward\n";
    else
      cout << "fantasy\n";
  }
  return 0;
}
