#include <bits/stdc++.h>
char s[100100];
char a[100100], b[100100], s1[100100], s2[100100];
int main() {
  int i, j, k, l, test, t = 1;
  scanf("%s", s);
  scanf("%s", s1);
  scanf("%s", s2);
  int start1 = 6 * 100100 + 10, end1 = -100100, start2 = 6 * 100100 + 10,
      end2 = -100100;
  int forward = 0, backward = 0;
  int fl;
  for (i = 0; s[i]; i++) {
    fl = 1;
    for (j = 0, k = i; s1[j]; j++, k++) {
      if (!s[k]) {
        fl = 0;
        break;
      }
      if (s1[j] != s[k]) {
        fl = 0;
        break;
      }
    }
    if (fl) {
      start1 = i;
      break;
    }
  }
  for (i = 0; s[i]; i++) {
    fl = 1;
    for (j = 0, k = i; s2[j]; j++, k++) {
      if (!s[k]) {
        fl = 0;
        break;
      }
      if (s2[j] != s[k]) {
        fl = 0;
        break;
      }
    }
    if (fl) {
      if (i > end2) end2 = i;
    }
  }
  l = strlen(s1);
  if (start1 + l - 1 < end2) forward = 1;
  if (start1 == 6 * 100100 + 10 || end2 == -100100) forward = 0;
  int l1, l2, l3;
  l1 = strlen(s);
  l2 = strlen(s1);
  l3 = strlen(s2);
  for (i = l1 - 1; i >= 0; i--) {
    fl = 1;
    for (j = 0, k = i; s1[j]; j++, k--) {
      if (k < 0) {
        fl = 0;
        break;
      }
      if (s1[j] != s[k]) {
        fl = 0;
        break;
      }
    }
    if (fl) {
      end1 = i;
      break;
    }
  }
  for (i = l1 - 1; i >= 0; i--) {
    fl = 1;
    for (j = 0, k = i; s2[j]; j++, k--) {
      if (k < 0) {
        fl = 0;
        break;
      }
      if (s2[j] != s[k]) {
        fl = 0;
        break;
      }
    }
    if (fl) {
      start2 = i;
    }
  }
  if (start2 < end1 - l2 + 1) backward = 1;
  if (forward && backward)
    printf("both\n");
  else if (backward)
    printf("backward\n");
  else if (forward)
    printf("forward\n");
  else
    printf("fantasy\n");
  return 0;
}
