/* NWERC 2006 * Sample solution to Printer Queue * By Mikael Goldmann */ import java.util.*; public class printerqueue_mg { static Scanner in=new Scanner(System.in); public static void main(String[] args) throws Exception { for (int N=in.nextInt(); N>0; --N){ int n=in.nextInt(), pos=in.nextInt(); int[] q=new int[n]; int[] nprio = new int[10]; for (int i=0; i0) { while (q[hd] != prio) hd=(hd+1)%n; q[hd]=-q[hd]; ++tm; if (hd==pos) res = tm; } } System.out.println(res); } } }