#include <bits/stdc++.h>
void rev(char *s, char *d) {
  int l = strlen(s);
  char *p = s + l - 1;
  char *q = d;
  while (*p) *q++ = *p--;
  *q = '\0';
}
int main() {
  bool a, b;
  char fcls[200001], acl[200001], bcl[200001], rcls[200001], *ch;
  a = b = false;
  scanf("%s %s %s", fcls, acl, bcl);
  rev(fcls, rcls);
  if ((ch = strstr(fcls, acl))) {
    if (strstr(ch + strlen(acl), bcl)) a = true;
  }
  if ((ch = strstr(rcls, acl))) {
    if (strstr(ch + strlen(acl), bcl)) b = true;
  }
  if (a && b)
    printf("both\n");
  else if (a && !b)
    printf("forward\n");
  else if (b && !a)
    printf("backward\n");
  else
    printf("fantasy\n");
  return 0;
}
