/* * Solution to Flipper */ import java.util.*; public class Flip { public static Scanner in; public static int pileNum; public static int card[]; public static int n; public static int m; public static char dir[]; public static String fold; public static void main(String[] args) { in = new Scanner(System.in); pileNum = 0; while (true) { n = in.nextInt(); if (n == 0) break; pileNum++; card = new int[n]; for (int i = 1; i <= n; i++) card[i-1] = i; dir = new char[n]; String temp = in.next(); for (int i = 0; i < temp.length(); i++) dir[i] = temp.charAt(i); fold = in.next(); process(); System.out.println("Pile " + pileNum); m = in.nextInt(); for (int i = 0; i < m; i++) { int query = in.nextInt(); System.out.print("Card " + query + " is a face "); if (dir[query-1] == 'U') System.out.println("up " + card[query-1] + "."); else System.out.println("down " + card[query-1] + "."); } } } public static void reverse(int s, int e) { for (int i = 0; i < (e-s+1)/2; i++) { swap(i+s,e-i); } } public static void swap(int a, int b) { int temp = card[a]; card[a] = card[b]; card[b] = temp; char ctemp = dir[a]; dir[a] = dir[b]; dir[b] = ctemp; } public static void flip(int s, int e) { for (int i = s; i <= e; i++) { if (dir[i] == 'U') dir[i] = 'D'; else dir[i] = 'U'; } } public static void process() { int lpos = 0; int rpos = n-1; for (int i = 0; i < fold.length(); i++) { if (fold.charAt(i) == 'L') { reverse(0,lpos); flip(0,lpos); lpos++; } else { reverse(rpos,n-1); flip(rpos,n-1); rpos--; } } if (fold.charAt(n-2) == 'L') { reverse(rpos,n-1); } else { reverse(0,lpos); reverse(0,n-1); } } }