Problem: Peter likes to travel by train. He likes it so much that on the train he falls asleep. 

Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour.

The boy started to memorize the order of the flags' colours that he had seen. But soon he fell asleep again. Unfortunately, he didn't sleep long, he woke up and went on memorizing the colours. Then he fell asleep again, and that time he slept till the end of the journey.

At the station he told his parents about what he was doing, and wrote two sequences of the colours that he had seen before and after his sleep, respectively.

Peter's parents know that their son likes to fantasize. They give you the list of the flags' colours at the stations that the train passes sequentially on the way from A to B, and ask you to find out if Peter could see those sequences on the way from A to B, or from B to A. Remember, please, that Peter had two periods of wakefulness.

Peter's parents put lowercase Latin letters for colours. The same letter stands for the same colour, different letters — for different colours.

Input

The input data contains three lines. The first line contains a non-empty string, whose length does not exceed 105, the string consists of lowercase Latin letters — the flags' colours at the stations on the way from A to B. On the way from B to A the train passes the same stations, but in reverse order. 

The second line contains the sequence, written by Peter during the first period of wakefulness. The third line contains the sequence, written during the second period of wakefulness. Both sequences are non-empty, consist of lowercase Latin letters, and the length of each does not exceed 100 letters. Each of the sequences is written in chronological order. 

Output

Output one of the four words without inverted commas: 

  * «forward» — if Peter could see such sequences only on the way from A to B; 
  * «backward» — if Peter could see such sequences on the way from B to A; 
  * «both» — if Peter could see such sequences both on the way from A to B, and on the way from B to A; 
  * «fantasy» — if Peter could not see such sequences. 

Examples

Input

atob
a
b


Output

forward


Input

aaacaaa
aca
aa


Output

both

Note

It is assumed that the train moves all the time, so one flag cannot be seen twice. There are no flags at stations A and B.

Solution (in JAVA):

Solution:
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author sandeepandey
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TrainAndPeter solver = new TrainAndPeter();
		solver.solve(1, in, out);
		out.close();
	}
}

class TrainAndPeter {
    public void solve(int testNumber, InputReader in, OutputWriter out) {

        boolean a   =   false;
        boolean b   =   false;
        boolean c   =   false;
        boolean d   =   false;
        String input    =   in.readString();
        String firstSeq =   in.readString();
        String secondSeq    =   in.readString();

        int lenCount    =   input.length();
        int firstSeqCount   =   firstSeq.length();
        int secondSeqCount  =   secondSeq.length();

        StringHash mainHasher   =   new ConcreteHasher(input,true);
        StringHash firstHasher  =   new ConcreteHasher(firstSeq,true);
        StringHash secondHasher =   new ConcreteHasher(secondSeq,true);

        long firstFwdHash       =   firstHasher.hash(0,firstSeqCount-1);
        long secondFwdHash      =   secondHasher.hash(0,secondSeqCount-1);
        int firstFoundAt = Integer.MIN_VALUE,secondFoundAt= Integer.MIN_VALUE;

        long[] hashArray    =   mainHasher.getForwardKSizeHashes(firstSeqCount,lenCount);
        for(int i   =   0;i < hashArray.length ; i++) {
            if(hashArray[i]==firstFwdHash) {
                firstFoundAt    =   i+firstSeqCount-1;
                break;
            }
        }
        hashArray       =   mainHasher.getForwardKSizeHashes(secondSeqCount,lenCount);

        for(int i   =   0;i < hashArray.length ; i++) {
            if(hashArray[i]==secondFwdHash) {
                secondFoundAt    =   i;
            }
        }
        int firstFixAt  = Integer.MIN_VALUE,secondFixAt=Integer.MIN_VALUE;

        long[] revHashArray =   mainHasher.getReverseKSizeHashes(firstSeqCount,lenCount);
        for(int i   =   revHashArray.length-1;i>=0 ; i--) {
            if(revHashArray[i]==firstFwdHash) {
                firstFixAt    =   i-secondSeqCount+1;
                break;
            }
        }

        revHashArray    =   mainHasher.getReverseKSizeHashes(secondSeqCount,lenCount);
        for(int i   =   revHashArray.length-1;i >=0 ; i--) {
            if(revHashArray[i]==secondFwdHash) {
                secondFixAt    =   i;

            }
        }
       if( firstFoundAt == Integer.MIN_VALUE || secondFoundAt == Integer.MIN_VALUE || (firstFoundAt >= secondFoundAt)) {
            a = false;
        }   else if(secondFoundAt > firstFoundAt) {
            a = true;
        }

        if(firstFixAt   ==  Integer.MIN_VALUE || secondFixAt == Integer.MIN_VALUE || (secondFixAt>=firstFixAt)){
              b=false;
        }  else {
            b   =   true;
        }

        if(a && b) {
            out.printLine("both");
        } else if(a && !b) {
            out.printLine("forward");
        } else if(!a && b) {
            out.printLine("backward");
        }  else {
            out.printLine("fantasy");
        }

    }
}

class InputReader {

    private InputStream stream;

    private byte[] buf = new byte[1024];

    private int curChar;

    private int numChars;

    private SpaceCharFilter filter;
    public InputReader(InputStream stream) {

        this.stream = stream;

    }



    public int read() {

        if (numChars == -1)

            throw new InputMismatchException();

        if (curChar >= numChars) {

            curChar = 0;

            try {

                numChars = stream.read(buf);

            } catch (IOException e) {

                throw new InputMismatchException();

            }

            if (numChars <= 0)

                return -1;

        }

        return buf[curChar++];

    }



    public String readString() {

        int c = read();

        while (isSpaceChar(c))

            c = read();

        StringBuffer res = new StringBuffer();

        do {

            res.appendCodePoint(c);

            c = read();

        } while (!isSpaceChar(c));

        return res.toString();

    }



    public boolean isSpaceChar(int c) {

        if (filter != null)

            return filter.isSpaceChar(c);

        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;

    }



    public interface SpaceCharFilter {

        public boolean isSpaceChar(int ch);

    }

}

class OutputWriter {

    private final PrintWriter writer;
    public OutputWriter(OutputStream outputStream) {

        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));

    }



    public OutputWriter(Writer writer) {
        this.writer = new PrintWriter(writer);
    }



    public void print(Object...objects) {

        for (int i = 0; i < objects.length; i++) {

            if (i != 0)

                writer.print(' ');

            writer.print(objects[i]);

        }

    }



    public void printLine(Object...objects) {

        print(objects);

        writer.println();

    }



    public void close() {

        writer.close();

    }



    }

interface  StringHash {
    /**
     * This interface is the base interface of all the actvities involve in String matching via roll hashing
     * programmer are advise to use this interface as the base interface of all other concrete subclasses.
     */
    public long hash(int from,int to);
    public long[] getForwardKSizeHashes(int windowSize,int length);
    public long[] getReverseKSizeHashes(int windowSize,int length);
    }

class ConcreteHasher extends SimpleStringHash {

    public ConcreteHasher(String input,boolean isReverseRequired) {
       super(input,isReverseRequired);
    }
    public long hashFunction(long previousHash, char currentChar, int subtractor, long multiplier) {
        return (previousHash * multiplier + currentChar-subtractor);
    }
    public long[] getForwardKSizeHashes(int windowSize,int length) {

        int hashCount   =   length-windowSize+1;
        long[] hashes   =   new long[hashCount];
        for(int i   =   0;i <( hashCount ); i++) {
            hashes[i]   =   hash(i,i+windowSize-1);
        }
        return hashes;
    }
    public long[] getReverseKSizeHashes(int windowSize,int length) {
        int hashCount   =   length-windowSize+1;
        long[] hashes   =   new long[hashCount];
        for(int i   =   0;i <( hashCount ); i++) {
            hashes[hashCount-i-1]   =   reverseHash(length-i-1,length-i-windowSize);
        }
        return hashes;

    }

}

abstract class SimpleStringHash extends AbstractStringHash {

    private long[] hashArray =   new long[0];
    private  long[] baseArray =   new long[0];
    private  long[] reverseHashArray  =   new long[0];
    private  int length;
    public SimpleStringHash(CharSequence input,boolean isReverseRequired) {
        super();
        length                  =   input.length();
        hashArray                   =   new long[length + 1];

        baseArray                   =   new long[length + 1];
        long tmpHash                =   0;
        long tmpMul                 =   1;

        for(int i   =   0; i < length ; i++) {
            baseArray[i]            =   tmpMul;
            tmpMul                  =   tmpMul * DEFAULT_MAULTIPLIER;
        }

        for(int i   =   0; i < length ; i++) {
            tmpHash                 =   hashFunction(tmpHash,input.charAt(i),48,DEFAULT_MAULTIPLIER);
            hashArray[i]            =   tmpHash;
        }
        if(isReverseRequired) {
            reverseHashArray            =   new long[length + 1];

            tmpHash =   0;
            for(int i   =   length-1 ; i >=0 ; i--) {
                tmpHash     =   hashFunction(tmpHash,input.charAt(i),48,DEFAULT_MAULTIPLIER);
                reverseHashArray[i]    =   tmpHash;
            }
        }

    }

    public abstract long hashFunction(long previousHash,char currentChar,int subtractor, long multiplier);

    public long hash(int from, int to) {

        int windowSize              =   to-from + 1;
      //  System.out.println("window Size::"+windowSize);
        if(from < 0 || to < 0) {
            return 0;
        }

        long collectedHash  = (hashArray[to]-((from <=0) ? 0 : hashArray[from-1] * baseArray[windowSize]));
        //System.out.println("Collected Hash::"+collectedHash);
        return collectedHash;
    }


    public long reverseHash(int from, int to) {

        int windowSize              =   from-to + 1;
        if(windowSize <= 0) {
            return 0;
        }
        long hashToReturn   =   reverseHashArray[to]- ((from == length-1) ? 0 : reverseHashArray[from+1] * baseArray[windowSize]);
        return hashToReturn;
    }
    }

abstract class AbstractStringHash implements StringHash {

    protected final long DEFAULT_MAULTIPLIER ;
    public AbstractStringHash() {
//        Random randomBehaviour  =   new Random(547315431513L + System.currentTimeMillis()) ;
//        int randomNumber        =   randomBehaviour.nextInt(Integer.MAX_VALUE);
//        randomNumber            =   IntegerUtils.nextPrime(randomNumber);
//
        DEFAULT_MAULTIPLIER     =   1000000007;
    }


    }