#include <bits/stdc++.h>
int main() {
  int now = 0, a = 0, b = 0, ans[4] = {-1, -1, -1, -1};
  bool f, s = false, q = false;
  char c[150000], l[200], r[200];
  for (int i = 0; i < 150000; i++) c[i] = '\0';
  for (int i = 0; i < 200; i++) l[i] = r[i] = '\0';
  scanf("%s", c);
  scanf("%s", l);
  while (l[a] != '\0') a++;
  scanf("%s", r);
  while (r[b] != '\0') b++;
  while (c[now] != '\0') {
    if (c[now] == l[0]) {
      if (ans[0] == -1) {
        f = true;
        for (int i = 1; i < a && f; i++)
          if (c[now + i] != l[i]) f = false;
        if (f) ans[0] = now;
      }
      if (now >= a - 1 && ans[2] != -1 && now - a >= ans[2]) {
        f = true;
        for (int i = 1; i < a && f; i++)
          if (c[now - i] != l[i]) f = false;
        if (f) ans[1] = now;
      }
    }
    if (c[now] == r[0]) {
      if (ans[0] + a <= now && ans[0] != -1) {
        f = true;
        for (int i = 1; i < b && f; i++)
          if (c[now + i] != r[i]) f = false;
        if (f) ans[3] = now;
      }
      if (now >= b - 1 && ans[2] == -1) {
        f = true;
        for (int i = 1; i < b && f; i++)
          if (c[now - i] != r[i]) f = false;
        if (f) ans[2] = now;
      }
    }
    now++;
  }
  if (ans[0] + a <= ans[3]) {
    if (ans[1] >= ans[2] && ans[2] != -1)
      printf("both\n");
    else
      printf("forward\n");
  } else if (ans[1] >= ans[2] && ans[2] != -1)
    printf("backward\n");
  else
    printf("fantasy\n");
}
