#include <bits/stdc++.h>
using namespace std;
string a, b, c;
int temp1 = 0, temp2 = 0, temp3 = 0;
int p = -1;
int main() {
  cin >> a >> b >> c;
  for (int i = 0; i < a.length() && p == -1; i++) {
    temp1 = 1;
    for (int j = 0; j < b.length() && temp1; j++) {
      if (a[i + j] != b[j]) {
        temp1 = 0;
        break;
      }
    }
    if (temp1 == 1) {
      p = i + b.length();
    }
  }
  if (p != -1) {
    for (int i = p; i < a.length() && !temp2; i++) {
      temp2 = 1;
      for (int j = 0; j < c.length() && temp2; j++) {
        if (a[i + j] != c[j]) {
          temp2 = 0;
          break;
        }
      }
    }
  }
  p = -1;
  for (int i = a.length() - 1; i >= 0 && p == -1; i--) {
    temp1 = 1;
    for (int j = 0; j < b.length() && temp1; j++) {
      if (a[i - j] != b[j]) {
        temp1 = 0;
        break;
      }
    }
    if (temp1 == 1) {
      p = i - b.length();
    }
  }
  if (p != -1) {
    for (int i = p; i >= 0 && !temp3; i--) {
      temp3 = 1;
      for (int j = 0; j < c.length() && temp3; j++) {
        if (a[i - j] != c[j]) {
          temp3 = 0;
          break;
        }
      }
    }
  }
  int ans = temp2 + temp3 * 2;
  switch (ans) {
    case 0:
      cout << "fantasy";
      break;
    case 1:
      cout << "forward";
      break;
    case 2:
      cout << "backward";
      break;
    case 3:
      cout << "both";
      break;
  }
  return 0;
}
