Right and tfeL truncatable primes A right-truncatable prime is a prime where every prefix is a prime (in base 10).  A left-truncatable prime is exactly the opposite, where every postfix is a prime (primes that start with 0 aren't allowed).  Both of these sequences are finite (There are only 83 Right-truncatables, while there are 4260 Left-truncatables).

You need to write a program that accepts a single number as input, and produces the nth right-truncatable prime.  However, when the program is read arranged backwards, it should produce the nth left-truncatable prime.

To arrange a program backwards, we split the program into words, then reverse the order of the words.  A word can consist of any number of characters.

For example, if the following was your program:

hello world
1234567890


The following would all be allowed as possible backwards arrangements:

Splitting on each character:

0987654321
dlrow olleh


Splitting on whitespace:

1234567890
world hello


Splitting arbitrarily (pipes added for clarity):

hel|lo w|orld
1|23456|7|8|90

908723456orld
1lo whel


When arranging your program backwards, all whitespace must be considered and reversed, just like any other character.

Forward test inputs:

1:  2
2:  3
21: 379
60: 239933
83: 73939133


Backward test inputs:

1:    2
2:    3
39:   647
187:  29173
4260: 357686312646216567629137


Programs should be able to run in a reasonable amount of time (less than a minute)

This is a code-golf, so the program with the fewest bytes wins!
Jelly, 26 23 bytes

Forward

Ñ¶p9¶7ÆR2ĿV€$ÆPÐf$ÐĿFị@


Try it online!

Words

Ñ ¶ p 9 ¶ 7ÆR2ĿV€$ÆPÐf$ÐĿFị@

Backward

7ÆR2ĿV€$ÆPÐf$ÐĿFị@¶9p¶Ñ


Try it online!

Words

7ÆR2ĿV€$ÆPÐf$ÐĿFị@ ¶ 9 p ¶ Ñ

How it works

All Jelly programs consist of links (Jelly's take on functions), which are separated by linefeeds or pilcrows (¶). The last of them is the main link; it is called automatically when the program is run.

The forward program works as follows.

Ñ                   Helper link. Unused.


p9                  Helper link. Take the Cartesian product with [1, ..., 9].


7ÆR2ĿV€$ÆPÐf$ÐĿFị@  Main link. Argument: n

7ÆR                 Yield all primes up to 7.
             ÐĿ     
            $ÐĿ     Combine the two quicklinks to the left into a monadic chain,
                    and call it repeatedly until the results are no longer unique.
                    Return the array of all intermediate results.
       $              Combine the two links to the left into a monadic chain.
   2Ŀ               Call the helper link on line 2.
     Ṿ€                 Eval each array in the product. This casts to string
                        before evaluating, thus concatenating both numbers.
        ÆPÐf        Filter by primality; keep only primes.
               F    Flatten the resulting array.
                ị@  Retrieve the element at index n.


The backward program does almost exactly the same; there are only two differences.


The main link is now Ñ, which simply calls the link below it (wrapping around), i.e., the main link of the forward program.
9p instead of p9 return the reversed Cartesian product.