#8 A. Train and Peter
import re x = raw_input() y = raw_input() z = raw_input() m1 = re.search(y+".*"+z,x) m2 = re.search(z[::-1]+".*"+y[::-1],x) if m1 and not m2: print "forward" if not m1 and m2: print "backward" if m1 and m2: print "both" if not m1 and not m2: print "fantasy"