#include <bits/stdc++.h>
int good(char *s1, char *s2, char *s3) {
  return (s1 = strstr(s1, s2)) != NULL && strstr(s1 + strlen(s2), s3) != NULL;
}
void reverse(int n, char *s) {
  int i, j;
  for (i = 0, j = n - 1; i < j; i++, j--) {
    char tmp;
    tmp = s[i];
    s[i] = s[j];
    s[j] = tmp;
  }
}
int main() {
  static char s1[100000 + 1], s2[100 + 1], s3[100 + 1];
  int a, b, c, forward, backward;
  scanf("%s%s%s", s1, s2, s3);
  a = strlen(s1);
  b = strlen(s2);
  c = strlen(s3);
  forward = 0;
  if (good(s1, s2, s3)) forward = 1;
  reverse(a, s1);
  backward = 0;
  if (good(s1, s2, s3)) backward = 1;
  printf(forward && backward ? "both\n"
         : forward           ? "forward\n"
         : backward          ? "backward\n"
                             : "fantasy\n");
  return 0;
}
