#include <bits/stdc++.h>
char s[123456];
char a[123];
char b[123];
void reverse(char *s) {
  char r, *t;
  for (t = s + strlen(s) - 1; s < t; s++, t--) {
    r = *s, *s = *t, *t = r;
  }
}
int find(char *s, char *a, char *b) {
  return (s = strstr(s, a)) != NULL && strstr(s + strlen(a), b) != NULL;
}
int main() {
  scanf("%s%s%s", s, a, b);
  int f = find(s, a, b);
  reverse(s);
  int bb = find(s, a, b);
  if (f + bb == 2) {
    printf("both\n");
  } else if (f == 1) {
    printf("forward\n");
  } else if (bb == 1) {
    printf("backward\n");
  } else {
    printf("fantasy\n");
  }
  return 0;
}
