#include <bits/stdc++.h>
int main() {
  char s[100001], reversed[100001];
  char s_first[101], s_second[101];
  char *tryf1, *tryf2;
  int l;
  scanf("%s%s%s", s, s_first, s_second);
  for (int i = 0, l = strlen(s); i < l; i++) reversed[i] = s[l - i - 1];
  tryf1 = strstr(s, s_first);
  if (tryf1) tryf1 = strstr(tryf1 + strlen(s_first), s_second);
  tryf2 = strstr(reversed, s_first);
  if (tryf2) tryf2 = strstr(tryf2 + strlen(s_first), s_second);
  if (tryf1) {
    if (tryf2)
      puts("both");
    else
      puts("forward");
  } else {
    if (tryf2)
      puts("backward");
    else
      puts("fantasy");
  }
  return 0;
}
