package facebook.y2021.qual

private fun needed(s: String): Pair<Int, Int>? {
	return (s.count { it == '.' } to s.indexOf('.')).takeIf { 'O' !in s }
}

private fun solve(): String {
	val field = List(readInt()) { readLn() }
	val options = field.indices.flatMap { i -> listOf(
		needed(field[i])?.let { it.first to (i to it.second) },
		needed(field.map { it[i] }.joinToString(""))?.let { it.first to (it.second to i) }
	)}.filterNotNull()
	val needed = options.minOfOrNull { it.first } ?: return "Impossible"
	val goodOptions = options.filter { it.first == needed }
	val different = if (needed == 1) goodOptions.toSet().size else goodOptions.size
	return "$needed $different"
}

fun main() = repeat(readInt()) { println("Case #${it + 1}: ${solve()}") }

private fun readLn() = readLine()!!
private fun readInt() = readLn().toInt()

Compiled from "b.kt"
public final class facebook.y2021.qual.BKt {
  private static final kotlin.Pair<java.lang.Integer, java.lang.Integer> needed(java.lang.String);
    Code:
       0: aload_0
       1: checkcast     #9                  // class java/lang/CharSequence
       4: astore_1
       5: iconst_0
       6: istore_2
       7: iconst_0
       8: istore_3
       9: iconst_0
      10: istore        4
      12: iload         4
      14: aload_1
      15: invokeinterface #13,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      20: if_icmpge     64
      23: aload_1
      24: iload         4
      26: invokeinterface #17,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      31: istore        5
      33: iload         5
      35: istore        6
      37: iconst_0
      38: istore        7
      40: iload         6
      42: bipush        46
      44: if_icmpne     51
      47: iconst_1
      48: goto          52
      51: iconst_0
      52: ifeq          58
      55: iinc          3, 1
      58: iinc          4, 1
      61: goto          12
      64: iload_3
      65: invokestatic  #23                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      68: aload_0
      69: checkcast     #9                  // class java/lang/CharSequence
      72: bipush        46
      74: iconst_0
      75: iconst_0
      76: bipush        6
      78: aconst_null
      79: invokestatic  #29                 // Method kotlin/text/StringsKt.indexOf$default:(Ljava/lang/CharSequence;CIZILjava/lang/Object;)I
      82: invokestatic  #23                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      85: invokestatic  #35                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      88: astore_1
      89: aload_1
      90: astore_2
      91: iconst_0
      92: istore_3
      93: aload_0
      94: checkcast     #9                  // class java/lang/CharSequence
      97: bipush        79
      99: iconst_0
     100: iconst_2
     101: aconst_null
     102: invokestatic  #39                 // Method kotlin/text/StringsKt.contains$default:(Ljava/lang/CharSequence;CZILjava/lang/Object;)Z
     105: ifne          112
     108: iconst_1
     109: goto          113
     112: iconst_0
     113: ifeq          120
     116: aload_1
     117: goto          121
     120: aconst_null
     121: areturn

  private static final java.lang.String solve();
    Code:
       0: invokestatic  #61                 // Method readInt:()I
       3: istore_1
       4: new           #63                 // class java/util/ArrayList
       7: dup
       8: iload_1
       9: invokespecial #67                 // Method java/util/ArrayList."<init>":(I)V
      12: astore_2
      13: iconst_0
      14: istore_3
      15: iload_3
      16: iload_1
      17: if_icmpge     49
      20: iload_3
      21: istore        4
      23: aload_2
      24: iload         4
      26: istore        5
      28: astore        24
      30: iconst_0
      31: istore        6
      33: invokestatic  #70                 // Method readLn:()Ljava/lang/String;
      36: aload         24
      38: swap
      39: invokevirtual #74                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
      42: pop
      43: iinc          3, 1
      46: goto          15
      49: aload_2
      50: checkcast     #76                 // class java/util/List
      53: astore_0
      54: aload_0
      55: checkcast     #78                 // class java/util/Collection
      58: invokestatic  #84                 // Method kotlin/collections/CollectionsKt.getIndices:(Ljava/util/Collection;)Lkotlin/ranges/IntRange;
      61: checkcast     #86                 // class java/lang/Iterable
      64: astore_2
      65: iconst_0
      66: istore_3
      67: aload_2
      68: astore        4
      70: new           #63                 // class java/util/ArrayList
      73: dup
      74: invokespecial #89                 // Method java/util/ArrayList."<init>":()V
      77: checkcast     #78                 // class java/util/Collection
      80: astore        5
      82: iconst_0
      83: istore        6
      85: aload         4
      87: invokeinterface #93,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      92: astore        7
      94: aload         7
      96: invokeinterface #99,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     101: ifeq          404
     104: aload         7
     106: checkcast     #101                // class kotlin/collections/IntIterator
     109: invokevirtual #104                // Method kotlin/collections/IntIterator.nextInt:()I
     112: istore        8
     114: iload         8
     116: istore        9
     118: iconst_0
     119: istore        10
     121: iconst_2
     122: anewarray     #56                 // class kotlin/Pair
     125: astore        11
     127: aload         11
     129: iconst_0
     130: aload_0
     131: iload         9
     133: invokeinterface #108,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     138: checkcast     #54                 // class java/lang/String
     141: invokestatic  #110                // Method needed:(Ljava/lang/String;)Lkotlin/Pair;
     144: dup
     145: ifnull        189
     148: astore        12
     150: istore        13
     152: astore        14
     154: iconst_0
     155: istore        15
     157: aload         12
     159: invokevirtual #114                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     162: iload         9
     164: invokestatic  #23                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     167: aload         12
     169: invokevirtual #117                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     172: invokestatic  #35                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     175: invokestatic  #35                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     178: astore        16
     180: aload         14
     182: iload         13
     184: aload         16
     186: goto          191
     189: pop
     190: aconst_null
     191: aastore
     192: aload         11
     194: iconst_1
     195: aload_0
     196: checkcast     #86                 // class java/lang/Iterable
     199: astore        17
     201: istore        13
     203: astore        14
     205: iconst_0
     206: istore        12
     208: aload         17
     210: astore        15
     212: new           #63                 // class java/util/ArrayList
     215: dup
     216: aload         17
     218: bipush        10
     220: invokestatic  #121                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     223: invokespecial #67                 // Method java/util/ArrayList."<init>":(I)V
     226: checkcast     #78                 // class java/util/Collection
     229: astore        18
     231: iconst_0
     232: istore        19
     234: aload         15
     236: invokeinterface #93,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     241: astore        20
     243: aload         20
     245: invokeinterface #99,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     250: ifeq          298
     253: aload         20
     255: invokeinterface #124,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     260: astore        21
     262: aload         18
     264: aload         21
     266: checkcast     #54                 // class java/lang/String
     269: astore        22
     271: astore        16
     273: iconst_0
     274: istore        23
     276: aload         22
     278: iload         9
     280: invokevirtual #125                // Method java/lang/String.charAt:(I)C
     283: invokestatic  #130                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     286: aload         16
     288: swap
     289: invokeinterface #131,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     294: pop
     295: goto          243
     298: aload         18
     300: checkcast     #76                 // class java/util/List
     303: nop
     304: astore        16
     306: aload         14
     308: iload         13
     310: aload         16
     312: checkcast     #86                 // class java/lang/Iterable
     315: ldc           #133                // String
     317: checkcast     #9                  // class java/lang/CharSequence
     320: aconst_null
     321: aconst_null
     322: iconst_0
     323: aconst_null
     324: aconst_null
     325: bipush        62
     327: aconst_null
     328: invokestatic  #137                // Method kotlin/collections/CollectionsKt.joinToString$default:(Ljava/lang/Iterable;Ljava/lang/CharSequence;Ljava/lang/CharSequence;Ljava/lang/CharSequence;ILjava/lang/CharSequence;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
     331: invokestatic  #110                // Method needed:(Ljava/lang/String;)Lkotlin/Pair;
     334: dup
     335: ifnull        379
     338: astore        12
     340: istore        13
     342: astore        14
     344: iconst_0
     345: istore        15
     347: aload         12
     349: invokevirtual #114                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     352: aload         12
     354: invokevirtual #117                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     357: iload         9
     359: invokestatic  #23                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     362: invokestatic  #35                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     365: invokestatic  #35                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     368: astore        16
     370: aload         14
     372: iload         13
     374: aload         16
     376: goto          381
     379: pop
     380: aconst_null
     381: aastore
     382: aload         11
     384: invokestatic  #141                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     387: checkcast     #86                 // class java/lang/Iterable
     390: nop
     391: astore        9
     393: aload         5
     395: aload         9
     397: invokestatic  #145                // Method kotlin/collections/CollectionsKt.addAll:(Ljava/util/Collection;Ljava/lang/Iterable;)Z
     400: pop
     401: goto          94
     404: aload         5
     406: checkcast     #76                 // class java/util/List
     409: nop
     410: checkcast     #86                 // class java/lang/Iterable
     413: invokestatic  #149                // Method kotlin/collections/CollectionsKt.filterNotNull:(Ljava/lang/Iterable;)Ljava/util/List;
     416: astore_1
     417: aload_1
     418: checkcast     #86                 // class java/lang/Iterable
     421: invokeinterface #93,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     426: astore        5
     428: aload         5
     430: invokeinterface #99,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     435: ifne          442
     438: aconst_null
     439: goto          541
     442: aload         5
     444: invokeinterface #124,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     449: checkcast     #56                 // class kotlin/Pair
     452: astore        6
     454: iconst_0
     455: istore        7
     457: aload         6
     459: invokevirtual #114                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     462: checkcast     #151                // class java/lang/Number
     465: invokevirtual #154                // Method java/lang/Number.intValue:()I
     468: invokestatic  #23                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     471: checkcast     #156                // class java/lang/Comparable
     474: astore        6
     476: aload         5
     478: invokeinterface #99,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     483: ifeq          539
     486: aload         5
     488: invokeinterface #124,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     493: checkcast     #56                 // class kotlin/Pair
     496: astore        7
     498: iconst_0
     499: istore        8
     501: aload         7
     503: invokevirtual #114                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     506: checkcast     #151                // class java/lang/Number
     509: invokevirtual #154                // Method java/lang/Number.intValue:()I
     512: invokestatic  #23                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     515: checkcast     #156                // class java/lang/Comparable
     518: astore        7
     520: aload         6
     522: aload         7
     524: invokeinterface #160,  2          // InterfaceMethod java/lang/Comparable.compareTo:(Ljava/lang/Object;)I
     529: ifle          476
     532: aload         7
     534: astore        6
     536: goto          476
     539: aload         6
     541: checkcast     #19                 // class java/lang/Integer
     544: dup
     545: ifnull        554
     548: invokevirtual #161                // Method java/lang/Integer.intValue:()I
     551: goto          558
     554: pop
     555: ldc           #163                // String Impossible
     557: areturn
     558: istore_2
     559: aload_1
     560: checkcast     #86                 // class java/lang/Iterable
     563: astore        4
     565: iconst_0
     566: istore        5
     568: aload         4
     570: astore        6
     572: new           #63                 // class java/util/ArrayList
     575: dup
     576: invokespecial #89                 // Method java/util/ArrayList."<init>":()V
     579: checkcast     #78                 // class java/util/Collection
     582: astore        7
     584: iconst_0
     585: istore        8
     587: aload         6
     589: invokeinterface #93,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     594: astore        9
     596: aload         9
     598: invokeinterface #99,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     603: ifeq          661
     606: aload         9
     608: invokeinterface #124,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     613: astore        10
     615: aload         10
     617: checkcast     #56                 // class kotlin/Pair
     620: astore        11
     622: iconst_0
     623: istore        12
     625: aload         11
     627: invokevirtual #114                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     630: checkcast     #151                // class java/lang/Number
     633: invokevirtual #154                // Method java/lang/Number.intValue:()I
     636: iload_2
     637: if_icmpne     644
     640: iconst_1
     641: goto          645
     644: iconst_0
     645: ifeq          596
     648: aload         7
     650: aload         10
     652: invokeinterface #131,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     657: pop
     658: goto          596
     661: aload         7
     663: checkcast     #76                 // class java/util/List
     666: nop
     667: astore_3
     668: iload_2
     669: iconst_1
     670: if_icmpne     688
     673: aload_3
     674: checkcast     #86                 // class java/lang/Iterable
     677: invokestatic  #167                // Method kotlin/collections/CollectionsKt.toSet:(Ljava/lang/Iterable;)Ljava/util/Set;
     680: invokeinterface #172,  1          // InterfaceMethod java/util/Set.size:()I
     685: goto          694
     688: aload_3
     689: invokeinterface #173,  1          // InterfaceMethod java/util/List.size:()I
     694: istore        4
     696: new           #175                // class java/lang/StringBuilder
     699: dup
     700: invokespecial #176                // Method java/lang/StringBuilder."<init>":()V
     703: iload_2
     704: invokevirtual #180                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     707: bipush        32
     709: invokevirtual #183                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     712: iload         4
     714: invokevirtual #180                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     717: invokevirtual #186                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     720: areturn

  public static final void main();
    Code:
       0: invokestatic  #61                 // Method readInt:()I
       3: istore_0
       4: iconst_0
       5: istore_1
       6: iload_1
       7: iload_0
       8: if_icmpge     61
      11: iload_1
      12: istore_2
      13: iconst_0
      14: istore_3
      15: new           #175                // class java/lang/StringBuilder
      18: dup
      19: invokespecial #176                // Method java/lang/StringBuilder."<init>":()V
      22: ldc           #223                // String Case #
      24: invokevirtual #226                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      27: iload_2
      28: iconst_1
      29: iadd
      30: invokevirtual #180                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      33: ldc           #228                // String :
      35: invokevirtual #226                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      38: invokestatic  #230                // Method solve:()Ljava/lang/String;
      41: invokevirtual #226                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      44: invokevirtual #186                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      47: getstatic     #236                // Field java/lang/System.out:Ljava/io/PrintStream;
      50: swap
      51: invokevirtual #242                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      54: nop
      55: iinc          1, 1
      58: goto          6
      61: return

  private static final java.lang.String readLn();
    Code:
       0: invokestatic  #248                // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
       3: dup
       4: invokestatic  #253                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
       7: areturn

  private static final int readInt();
    Code:
       0: invokestatic  #70                 // Method readLn:()Ljava/lang/String;
       3: invokestatic  #257                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
       6: ireturn

  public static void main(java.lang.String[]);
    Code:
       0: invokestatic  #260                // Method main:()V
       3: return
}


package facebook.y2021.qual

private fun solve(): Int {
	val n = readInt()
	val c = readInts()
	val nei = List(n) { mutableListOf<Int>() }
	repeat(n - 1) {
		val (v, u) = readInts().map { it - 1 }
		nei[v].add(u)
		nei[u].add(v)
	}
	fun dfs(v: Int, p: Int): Int {
		return c[v] + ((nei[v] - p).maxOfOrNull { dfs(it, v) } ?: 0)
	}
	return c[0] + nei[0].map { dfs(it, 0) }.sorted().takeLast(2).sum()
}

fun main() = repeat(readInt()) { println("Case #${it + 1}: ${solve()}") }

private fun readLn() = readLine()!!
private fun readInt() = readLn().toInt()
private fun readStrings() = readLn().split(" ")
private fun readInts() = readStrings().map { it.toInt() }

Compiled from "c1.kt"
public final class facebook.y2021.qual.C1Kt {
  private static final int solve();
    Code:
       0: invokestatic  #9                  // Method readInt:()I
       3: istore_0
       4: invokestatic  #13                 // Method readInts:()Ljava/util/List;
       7: astore_1
       8: new           #15                 // class java/util/ArrayList
      11: dup
      12: iload_0
      13: invokespecial #19                 // Method java/util/ArrayList."<init>":(I)V
      16: astore_3
      17: iconst_0
      18: istore        4
      20: iload         4
      22: iload_0
      23: if_icmpge     64
      26: iload         4
      28: istore        5
      30: aload_3
      31: iload         5
      33: istore        6
      35: astore        18
      37: iconst_0
      38: istore        7
      40: new           #15                 // class java/util/ArrayList
      43: dup
      44: invokespecial #22                 // Method java/util/ArrayList."<init>":()V
      47: checkcast     #24                 // class java/util/List
      50: nop
      51: aload         18
      53: swap
      54: invokevirtual #28                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
      57: pop
      58: iinc          4, 1
      61: goto          20
      64: aload_3
      65: checkcast     #24                 // class java/util/List
      68: astore_2
      69: iload_0
      70: iconst_1
      71: isub
      72: istore_3
      73: iconst_0
      74: istore        4
      76: iload         4
      78: iload_3
      79: if_icmpge     281
      82: iload         4
      84: istore        5
      86: iconst_0
      87: istore        6
      89: invokestatic  #13                 // Method readInts:()Ljava/util/List;
      92: checkcast     #30                 // class java/lang/Iterable
      95: astore        7
      97: iconst_0
      98: istore        8
     100: aload         7
     102: astore        9
     104: new           #15                 // class java/util/ArrayList
     107: dup
     108: aload         7
     110: bipush        10
     112: invokestatic  #36                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     115: invokespecial #19                 // Method java/util/ArrayList."<init>":(I)V
     118: checkcast     #38                 // class java/util/Collection
     121: astore        10
     123: iconst_0
     124: istore        11
     126: aload         9
     128: invokeinterface #42,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     133: astore        12
     135: aload         12
     137: invokeinterface #48,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     142: ifeq          190
     145: aload         12
     147: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     152: astore        13
     154: aload         10
     156: aload         13
     158: checkcast     #54                 // class java/lang/Number
     161: invokevirtual #57                 // Method java/lang/Number.intValue:()I
     164: istore        14
     166: astore        15
     168: iconst_0
     169: istore        16
     171: iload         14
     173: iconst_1
     174: isub
     175: invokestatic  #63                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     178: aload         15
     180: swap
     181: invokeinterface #64,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     186: pop
     187: goto          135
     190: aload         10
     192: checkcast     #24                 // class java/util/List
     195: nop
     196: astore        17
     198: aload         17
     200: iconst_0
     201: invokeinterface #68,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     206: checkcast     #54                 // class java/lang/Number
     209: invokevirtual #57                 // Method java/lang/Number.intValue:()I
     212: istore        7
     214: aload         17
     216: iconst_1
     217: invokeinterface #68,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     222: checkcast     #54                 // class java/lang/Number
     225: invokevirtual #57                 // Method java/lang/Number.intValue:()I
     228: istore        8
     230: aload_2
     231: iload         7
     233: invokeinterface #68,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     238: checkcast     #24                 // class java/util/List
     241: iload         8
     243: invokestatic  #63                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     246: invokeinterface #69,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     251: pop
     252: aload_2
     253: iload         8
     255: invokeinterface #68,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     260: checkcast     #24                 // class java/util/List
     263: iload         7
     265: invokestatic  #63                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     268: invokeinterface #69,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     273: pop
     274: nop
     275: iinc          4, 1
     278: goto          76
     281: aload_1
     282: iconst_0
     283: invokeinterface #68,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     288: checkcast     #54                 // class java/lang/Number
     291: invokevirtual #57                 // Method java/lang/Number.intValue:()I
     294: aload_2
     295: iconst_0
     296: invokeinterface #68,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     301: checkcast     #30                 // class java/lang/Iterable
     304: astore_3
     305: istore        18
     307: iconst_0
     308: istore        4
     310: aload_3
     311: astore        5
     313: new           #15                 // class java/util/ArrayList
     316: dup
     317: aload_3
     318: bipush        10
     320: invokestatic  #36                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     323: invokespecial #19                 // Method java/util/ArrayList."<init>":(I)V
     326: checkcast     #38                 // class java/util/Collection
     329: astore        6
     331: iconst_0
     332: istore        7
     334: aload         5
     336: invokeinterface #42,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     341: astore        8
     343: aload         8
     345: invokeinterface #48,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     350: ifeq          402
     353: aload         8
     355: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     360: astore        9
     362: aload         6
     364: aload         9
     366: checkcast     #54                 // class java/lang/Number
     369: invokevirtual #57                 // Method java/lang/Number.intValue:()I
     372: istore        10
     374: astore        19
     376: iconst_0
     377: istore        11
     379: aload_1
     380: aload_2
     381: iload         10
     383: iconst_0
     384: invokestatic  #73                 // Method solve$dfs:(Ljava/util/List;Ljava/util/List;II)I
     387: invokestatic  #63                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     390: aload         19
     392: swap
     393: invokeinterface #64,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     398: pop
     399: goto          343
     402: aload         6
     404: checkcast     #24                 // class java/util/List
     407: nop
     408: astore        19
     410: iload         18
     412: aload         19
     414: checkcast     #30                 // class java/lang/Iterable
     417: invokestatic  #77                 // Method kotlin/collections/CollectionsKt.sorted:(Ljava/lang/Iterable;)Ljava/util/List;
     420: iconst_2
     421: invokestatic  #81                 // Method kotlin/collections/CollectionsKt.takeLast:(Ljava/util/List;I)Ljava/util/List;
     424: checkcast     #30                 // class java/lang/Iterable
     427: invokestatic  #85                 // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
     430: iadd
     431: ireturn

  public static final void main();
    Code:
       0: invokestatic  #9                  // Method readInt:()I
       3: istore_0
       4: iconst_0
       5: istore_1
       6: iload_1
       7: iload_0
       8: if_icmpge     61
      11: iload_1
      12: istore_2
      13: iconst_0
      14: istore_3
      15: new           #109                // class java/lang/StringBuilder
      18: dup
      19: invokespecial #110                // Method java/lang/StringBuilder."<init>":()V
      22: ldc           #112                // String Case #
      24: invokevirtual #116                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      27: iload_2
      28: iconst_1
      29: iadd
      30: invokevirtual #119                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      33: ldc           #121                // String :
      35: invokevirtual #116                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      38: invokestatic  #123                // Method solve:()I
      41: invokevirtual #119                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      44: invokevirtual #127                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      47: getstatic     #133                // Field java/lang/System.out:Ljava/io/PrintStream;
      50: swap
      51: invokevirtual #139                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      54: nop
      55: iinc          1, 1
      58: goto          6
      61: return

  private static final java.lang.String readLn();
    Code:
       0: invokestatic  #146                // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
       3: dup
       4: invokestatic  #151                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
       7: areturn

  private static final int readInt();
    Code:
       0: invokestatic  #153                // Method readLn:()Ljava/lang/String;
       3: invokestatic  #157                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
       6: ireturn

  private static final java.util.List<java.lang.String> readStrings();
    Code:
       0: invokestatic  #153                // Method readLn:()Ljava/lang/String;
       3: checkcast     #161                // class java/lang/CharSequence
       6: iconst_1
       7: anewarray     #163                // class java/lang/String
      10: astore_0
      11: aload_0
      12: iconst_0
      13: ldc           #165                // String
      15: aastore
      16: aload_0
      17: iconst_0
      18: iconst_0
      19: bipush        6
      21: aconst_null
      22: invokestatic  #171                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      25: areturn

  private static final java.util.List<java.lang.Integer> readInts();
    Code:
       0: invokestatic  #174                // Method readStrings:()Ljava/util/List;
       3: checkcast     #30                 // class java/lang/Iterable
       6: astore_0
       7: iconst_0
       8: istore_1
       9: aload_0
      10: astore_2
      11: new           #15                 // class java/util/ArrayList
      14: dup
      15: aload_0
      16: bipush        10
      18: invokestatic  #36                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      21: invokespecial #19                 // Method java/util/ArrayList."<init>":(I)V
      24: checkcast     #38                 // class java/util/Collection
      27: astore_3
      28: iconst_0
      29: istore        4
      31: aload_2
      32: invokeinterface #42,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      37: astore        5
      39: aload         5
      41: invokeinterface #48,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      46: ifeq          92
      49: aload         5
      51: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      56: astore        6
      58: aload_3
      59: aload         6
      61: checkcast     #163                // class java/lang/String
      64: astore        7
      66: astore        9
      68: iconst_0
      69: istore        8
      71: aload         7
      73: invokestatic  #157                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      76: nop
      77: invokestatic  #63                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      80: aload         9
      82: swap
      83: invokeinterface #64,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      88: pop
      89: goto          39
      92: aload_3
      93: checkcast     #24                 // class java/util/List
      96: nop
      97: areturn

  public static void main(java.lang.String[]);
    Code:
       0: invokestatic  #179                // Method main:()V
       3: return

  private static final int solve$dfs(java.util.List<java.lang.Integer>, java.util.List<? extends java.util.List<java.lang.Integer>>, int, int);
    Code:
       0: aload_0
       1: iload_2
       2: invokeinterface #68,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
       7: checkcast     #54                 // class java/lang/Number
      10: invokevirtual #57                 // Method java/lang/Number.intValue:()I
      13: aload_1
      14: iload_2
      15: invokeinterface #68,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      20: checkcast     #30                 // class java/lang/Iterable
      23: iload_3
      24: invokestatic  #63                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      27: invokestatic  #186                // Method kotlin/collections/CollectionsKt.minus:(Ljava/lang/Iterable;Ljava/lang/Object;)Ljava/util/List;
      30: checkcast     #30                 // class java/lang/Iterable
      33: astore        4
      35: istore        9
      37: aload         4
      39: invokeinterface #42,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      44: astore        5
      46: aload         5
      48: invokeinterface #48,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      53: ifne          60
      56: aconst_null
      57: goto          159
      60: aload         5
      62: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      67: checkcast     #54                 // class java/lang/Number
      70: invokevirtual #57                 // Method java/lang/Number.intValue:()I
      73: istore        6
      75: iconst_0
      76: istore        7
      78: aload_0
      79: aload_1
      80: iload         6
      82: iload_2
      83: invokestatic  #73                 // Method solve$dfs:(Ljava/util/List;Ljava/util/List;II)I
      86: invokestatic  #63                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      89: checkcast     #188                // class java/lang/Comparable
      92: astore        6
      94: aload         5
      96: invokeinterface #48,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     101: ifeq          157
     104: aload         5
     106: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     111: checkcast     #54                 // class java/lang/Number
     114: invokevirtual #57                 // Method java/lang/Number.intValue:()I
     117: istore        7
     119: iconst_0
     120: istore        8
     122: aload_0
     123: aload_1
     124: iload         7
     126: iload_2
     127: invokestatic  #73                 // Method solve$dfs:(Ljava/util/List;Ljava/util/List;II)I
     130: invokestatic  #63                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     133: checkcast     #188                // class java/lang/Comparable
     136: astore        7
     138: aload         6
     140: aload         7
     142: invokeinterface #192,  2          // InterfaceMethod java/lang/Comparable.compareTo:(Ljava/lang/Object;)I
     147: ifge          94
     150: aload         7
     152: astore        6
     154: goto          94
     157: aload         6
     159: astore        10
     161: iload         9
     163: aload         10
     165: checkcast     #59                 // class java/lang/Integer
     168: dup
     169: ifnull        178
     172: invokevirtual #193                // Method java/lang/Integer.intValue:()I
     175: goto          180
     178: pop
     179: iconst_0
     180: iadd
     181: ireturn
}


package facebook.y2021.qual

private fun solve(from: Char = 'A', toInclusive: Char = 'Z'): Int {
	val s = readLn()
	val letters = toInclusive - from + 1
	val inf = letters + 1
	val e = List(letters) { IntArray(letters) { inf } }
	repeat(readInt()) {
		val (u, v) = readLn().map { it - from }
		e[u][v] = 1
	}
	for (k in e.indices) {
		e[k][k] = 0
		for (i in e.indices) {
			for (j in e.indices) {
				e[i][j] = minOf(e[i][j], e[i][k] + e[k][j])
			}
		}
	}
	fun cost(k: Int): Int? {
		return s.sumOf { c -> e[c - from][k].also { if (it == inf) return null } }
	}
	return e.indices.mapNotNull { cost(it) }.minOrNull() ?: -1
}

fun main() = repeat(readInt()) { println("Case #${it + 1}: ${solve()}") }

private fun readLn() = readLine()!!
private fun readInt() = readLn().toInt()

Compiled from "a2.kt"
public final class facebook.y2021.qual.A2Kt {
  private static final int solve(char, char);
    Code:
       0: invokestatic  #10                 // Method readLn:()Ljava/lang/String;
       3: astore_2
       4: iload_1
       5: iload_0
       6: isub
       7: iconst_1
       8: iadd
       9: istore_3
      10: iload_3
      11: iconst_1
      12: iadd
      13: istore        4
      15: new           #12                 // class java/util/ArrayList
      18: dup
      19: iload_3
      20: invokespecial #16                 // Method java/util/ArrayList."<init>":(I)V
      23: astore        6
      25: iconst_0
      26: istore        7
      28: iload         7
      30: iload_3
      31: if_icmpge     95
      34: iload         7
      36: istore        8
      38: aload         6
      40: iload         8
      42: istore        9
      44: astore        22
      46: iconst_0
      47: istore        10
      49: iconst_0
      50: istore        11
      52: iload_3
      53: newarray       int
      55: astore        12
      57: iload         11
      59: iload_3
      60: if_icmpge     80
      63: iload         11
      65: istore        13
      67: aload         12
      69: iload         13
      71: iload         4
      73: iastore
      74: iinc          11, 1
      77: goto          57
      80: aload         12
      82: aload         22
      84: swap
      85: invokevirtual #20                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
      88: pop
      89: iinc          7, 1
      92: goto          28
      95: aload         6
      97: checkcast     #22                 // class java/util/List
     100: astore        5
     102: invokestatic  #26                 // Method readInt:()I
     105: istore        6
     107: iconst_0
     108: istore        7
     110: iload         7
     112: iload         6
     114: if_icmpge     283
     117: iload         7
     119: istore        8
     121: iconst_0
     122: istore        9
     124: invokestatic  #10                 // Method readLn:()Ljava/lang/String;
     127: checkcast     #28                 // class java/lang/CharSequence
     130: astore        10
     132: iconst_0
     133: istore        11
     135: aload         10
     137: astore        12
     139: new           #12                 // class java/util/ArrayList
     142: dup
     143: aload         10
     145: invokeinterface #31,  1           // InterfaceMethod java/lang/CharSequence.length:()I
     150: invokespecial #16                 // Method java/util/ArrayList."<init>":(I)V
     153: checkcast     #33                 // class java/util/Collection
     156: astore        13
     158: iconst_0
     159: istore        14
     161: iconst_0
     162: istore        15
     164: iload         15
     166: aload         12
     168: invokeinterface #31,  1           // InterfaceMethod java/lang/CharSequence.length:()I
     173: if_icmpge     220
     176: aload         12
     178: iload         15
     180: invokeinterface #37,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     185: istore        16
     187: aload         13
     189: iload         16
     191: istore        17
     193: astore        18
     195: iconst_0
     196: istore        19
     198: iload         17
     200: iload_0
     201: isub
     202: invokestatic  #43                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     205: aload         18
     207: swap
     208: invokeinterface #44,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     213: pop
     214: iinc          15, 1
     217: goto          164
     220: aload         13
     222: checkcast     #22                 // class java/util/List
     225: nop
     226: astore        20
     228: aload         20
     230: iconst_0
     231: invokeinterface #48,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     236: checkcast     #50                 // class java/lang/Number
     239: invokevirtual #53                 // Method java/lang/Number.intValue:()I
     242: istore        10
     244: aload         20
     246: iconst_1
     247: invokeinterface #48,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     252: checkcast     #50                 // class java/lang/Number
     255: invokevirtual #53                 // Method java/lang/Number.intValue:()I
     258: istore        11
     260: aload         5
     262: iload         10
     264: invokeinterface #48,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     269: checkcast     #55                 // class "[I"
     272: iload         11
     274: iconst_1
     275: iastore
     276: nop
     277: iinc          7, 1
     280: goto          110
     283: iconst_0
     284: istore        6
     286: aload         5
     288: checkcast     #33                 // class java/util/Collection
     291: invokeinterface #58,  1           // InterfaceMethod java/util/Collection.size:()I
     296: istore        7
     298: iload         6
     300: iload         7
     302: if_icmpge     447
     305: aload         5
     307: iload         6
     309: invokeinterface #48,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     314: checkcast     #55                 // class "[I"
     317: iload         6
     319: iconst_0
     320: iastore
     321: iconst_0
     322: istore        8
     324: aload         5
     326: checkcast     #33                 // class java/util/Collection
     329: invokeinterface #58,  1           // InterfaceMethod java/util/Collection.size:()I
     334: istore        9
     336: iload         8
     338: iload         9
     340: if_icmpge     441
     343: iconst_0
     344: istore        10
     346: aload         5
     348: checkcast     #33                 // class java/util/Collection
     351: invokeinterface #58,  1           // InterfaceMethod java/util/Collection.size:()I
     356: istore        11
     358: iload         10
     360: iload         11
     362: if_icmpge     435
     365: aload         5
     367: iload         8
     369: invokeinterface #48,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     374: checkcast     #55                 // class "[I"
     377: iload         10
     379: aload         5
     381: iload         8
     383: invokeinterface #48,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     388: checkcast     #55                 // class "[I"
     391: iload         10
     393: iaload
     394: aload         5
     396: iload         8
     398: invokeinterface #48,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     403: checkcast     #55                 // class "[I"
     406: iload         6
     408: iaload
     409: aload         5
     411: iload         6
     413: invokeinterface #48,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     418: checkcast     #55                 // class "[I"
     421: iload         10
     423: iaload
     424: iadd
     425: invokestatic  #64                 // Method java/lang/Math.min:(II)I
     428: iastore
     429: iinc          10, 1
     432: goto          358
     435: iinc          8, 1
     438: goto          336
     441: iinc          6, 1
     444: goto          298
     447: aload         5
     449: checkcast     #33                 // class java/util/Collection
     452: invokestatic  #70                 // Method kotlin/collections/CollectionsKt.getIndices:(Ljava/util/Collection;)Lkotlin/ranges/IntRange;
     455: checkcast     #72                 // class java/lang/Iterable
     458: astore        7
     460: iconst_0
     461: istore        8
     463: aload         7
     465: astore        9
     467: new           #12                 // class java/util/ArrayList
     470: dup
     471: invokespecial #75                 // Method java/util/ArrayList."<init>":()V
     474: checkcast     #33                 // class java/util/Collection
     477: astore        10
     479: iconst_0
     480: istore        11
     482: aload         9
     484: astore        12
     486: iconst_0
     487: istore        13
     489: aload         12
     491: invokeinterface #79,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     496: astore        14
     498: aload         14
     500: invokeinterface #85,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     505: ifeq          570
     508: aload         14
     510: checkcast     #87                 // class kotlin/collections/IntIterator
     513: invokevirtual #90                 // Method kotlin/collections/IntIterator.nextInt:()I
     516: istore        15
     518: iload         15
     520: istore        16
     522: iconst_0
     523: istore        17
     525: iload         16
     527: istore        18
     529: iconst_0
     530: istore        19
     532: aload_2
     533: aload         5
     535: iload_0
     536: iload         4
     538: iload         18
     540: invokestatic  #94                 // Method solve$cost:(Ljava/lang/String;Ljava/util/List;CII)Ljava/lang/Integer;
     543: dup
     544: ifnull        565
     547: astore        20
     549: iconst_0
     550: istore        21
     552: aload         10
     554: aload         20
     556: invokeinterface #44,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     561: pop
     562: goto          566
     565: pop
     566: nop
     567: goto          498
     570: nop
     571: aload         10
     573: checkcast     #22                 // class java/util/List
     576: nop
     577: checkcast     #72                 // class java/lang/Iterable
     580: invokestatic  #98                 // Method kotlin/collections/CollectionsKt.minOrNull:(Ljava/lang/Iterable;)Ljava/lang/Comparable;
     583: checkcast     #39                 // class java/lang/Integer
     586: dup
     587: ifnull        596
     590: invokevirtual #99                 // Method java/lang/Integer.intValue:()I
     593: goto          598
     596: pop
     597: iconst_m1
     598: ireturn

  static int solve$default(char, char, int, java.lang.Object);
    Code:
       0: iload_2
       1: iconst_1
       2: iand
       3: ifeq          9
       6: bipush        65
       8: istore_0
       9: iload_2
      10: iconst_2
      11: iand
      12: ifeq          18
      15: bipush        90
      17: istore_1
      18: iload_0
      19: iload_1
      20: invokestatic  #146                // Method solve:(CC)I
      23: ireturn

  public static final void main();
    Code:
       0: invokestatic  #26                 // Method readInt:()I
       3: istore_0
       4: iconst_0
       5: istore_1
       6: iload_1
       7: iload_0
       8: if_icmpge     65
      11: iload_1
      12: istore_2
      13: iconst_0
      14: istore_3
      15: new           #149                // class java/lang/StringBuilder
      18: dup
      19: invokespecial #150                // Method java/lang/StringBuilder."<init>":()V
      22: ldc           #152                // String Case #
      24: invokevirtual #156                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      27: iload_2
      28: iconst_1
      29: iadd
      30: invokevirtual #159                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      33: ldc           #161                // String :
      35: invokevirtual #156                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      38: iconst_0
      39: iconst_0
      40: iconst_3
      41: aconst_null
      42: invokestatic  #163                // Method solve$default:(CCILjava/lang/Object;)I
      45: invokevirtual #159                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      48: invokevirtual #166                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      51: getstatic     #172                // Field java/lang/System.out:Ljava/io/PrintStream;
      54: swap
      55: invokevirtual #178                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      58: nop
      59: iinc          1, 1
      62: goto          6
      65: return

  private static final java.lang.String readLn();
    Code:
       0: invokestatic  #184                // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
       3: dup
       4: invokestatic  #189                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
       7: areturn

  private static final int readInt();
    Code:
       0: invokestatic  #10                 // Method readLn:()Ljava/lang/String;
       3: invokestatic  #193                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
       6: ireturn

  public static void main(java.lang.String[]);
    Code:
       0: invokestatic  #196                // Method main:()V
       3: return

  private static final java.lang.Integer solve$cost(java.lang.String, java.util.List<int[]>, char, int, int);
    Code:
       0: aload_0
       1: checkcast     #28                 // class java/lang/CharSequence
       4: astore        5
       6: iconst_0
       7: istore        6
       9: iconst_0
      10: istore        7
      12: iload         7
      14: aload         5
      16: invokeinterface #31,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      21: if_icmpge     97
      24: aload         5
      26: iload         7
      28: invokeinterface #37,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      33: istore        8
      35: iload         6
      37: iload         8
      39: istore        9
      41: istore        14
      43: iconst_0
      44: istore        10
      46: aload_1
      47: iload         9
      49: iload_2
      50: isub
      51: invokeinterface #48,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      56: checkcast     #55                 // class "[I"
      59: iload         4
      61: iaload
      62: istore        11
      64: iload         11
      66: istore        12
      68: iconst_0
      69: istore        13
      71: iload         12
      73: iload_3
      74: if_icmpne     79
      77: aconst_null
      78: areturn
      79: iload         11
      81: nop
      82: istore        15
      84: iload         14
      86: iload         15
      88: iadd
      89: istore        6
      91: iinc          7, 1
      94: goto          12
      97: iload         6
      99: invokestatic  #43                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     102: areturn
}


package facebook.y2021.round1

private fun solve(M: Int = 1_000_000_007): Int {
	readLn()
	val s = readLn()

	var firstChar = 0.toChar()
	var lastChar = 0.toChar()
	var firstPos = -1
	var lastPos = -1
	var length = 0
	var pairs = 0
	var leftTicks = 0
	var rightTicks = 0
	var answer = 0

	for (i in s.indices) {
		if (s[i] == 'F') {
			rightTicks = (rightTicks + pairs) % M
			answer = (answer + leftTicks) % M
			length = (length + 1) % M
			continue
		}
		if (s[i] == '.') {
			val oldPairs = pairs
			pairs = (2 * pairs) % M
			if (firstChar != 0.toChar()) {
				answer = ((2 * answer + (leftTicks + rightTicks).toLong() * length) % M).toInt()
				leftTicks = ((leftTicks * 2 + length.toLong() * oldPairs) % M).toInt()
				rightTicks = ((rightTicks * 2 + length.toLong() * oldPairs) % M).toInt()
				if (firstChar != lastChar) {
					pairs = (pairs + 1) % M
					answer = ((answer + (lastPos + 1).toLong() * (length - firstPos + M)) % M).toInt()
					leftTicks = (leftTicks + lastPos + 1) % M
					rightTicks = ((rightTicks.toLong() + length - firstPos + M) % M).toInt()
				}
				lastPos = (lastPos + length) % M
			}
			length = (2 * length) % M
			continue
		}
		if (firstChar == 0.toChar()) {
			firstChar = s[i]
			lastChar = s[i]
			firstPos = length
			lastPos = length
			length = (length + 1) % M
			continue
		}
		rightTicks = (rightTicks + pairs) % M
		answer = (answer + leftTicks) % M
		if (s[i] != lastChar) {
			leftTicks = (leftTicks + lastPos + 1) % M
			rightTicks = (rightTicks + 1) % M
			answer = (answer + lastPos + 1) % M
			pairs = (pairs + 1) % M
		}
		lastPos = length
		lastChar = s[i]
		length = (length + 1) % M
	}
	return answer
}

fun main() = repeat(readInt()) { println("Case #${it + 1}: ${solve()}") }

private fun readLn() = readLine()!!
private fun readInt() = readLn().toInt()

Compiled from "a3.kt"
public final class facebook.y2021.round1.A3Kt {
  private static final int solve(int);
    Code:
       0: invokestatic  #10                 // Method readLn:()Ljava/lang/String;
       3: pop
       4: invokestatic  #10                 // Method readLn:()Ljava/lang/String;
       7: astore_1
       8: iconst_0
       9: istore_2
      10: iconst_0
      11: istore_3
      12: iconst_m1
      13: istore        4
      15: iconst_m1
      16: istore        5
      18: iconst_0
      19: istore        6
      21: iconst_0
      22: istore        7
      24: iconst_0
      25: istore        8
      27: iconst_0
      28: istore        9
      30: iconst_0
      31: istore        10
      33: iconst_0
      34: istore        11
      36: aload_1
      37: checkcast     #12                 // class java/lang/CharSequence
      40: invokeinterface #16,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      45: istore        12
      47: iload         11
      49: iload         12
      51: if_icmpge     397
      54: aload_1
      55: iload         11
      57: invokevirtual #22                 // Method java/lang/String.charAt:(I)C
      60: bipush        70
      62: if_icmpne     94
      65: iload         9
      67: iload         7
      69: iadd
      70: iload_0
      71: irem
      72: istore        9
      74: iload         10
      76: iload         8
      78: iadd
      79: iload_0
      80: irem
      81: istore        10
      83: iload         6
      85: iconst_1
      86: iadd
      87: iload_0
      88: irem
      89: istore        6
      91: goto          391
      94: aload_1
      95: iload         11
      97: invokevirtual #22                 // Method java/lang/String.charAt:(I)C
     100: bipush        46
     102: if_icmpne     269
     105: iload         7
     107: istore        13
     109: iconst_2
     110: iload         7
     112: imul
     113: iload_0
     114: irem
     115: istore        7
     117: iload_2
     118: ifeq          258
     121: iconst_2
     122: iload         10
     124: imul
     125: i2l
     126: iload         8
     128: iload         9
     130: iadd
     131: i2l
     132: iload         6
     134: i2l
     135: lmul
     136: ladd
     137: iload_0
     138: i2l
     139: lrem
     140: l2i
     141: istore        10
     143: iload         8
     145: iconst_2
     146: imul
     147: i2l
     148: iload         6
     150: i2l
     151: iload         13
     153: i2l
     154: lmul
     155: ladd
     156: iload_0
     157: i2l
     158: lrem
     159: l2i
     160: istore        8
     162: iload         9
     164: iconst_2
     165: imul
     166: i2l
     167: iload         6
     169: i2l
     170: iload         13
     172: i2l
     173: lmul
     174: ladd
     175: iload_0
     176: i2l
     177: lrem
     178: l2i
     179: istore        9
     181: iload_2
     182: iload_3
     183: if_icmpeq     249
     186: iload         7
     188: iconst_1
     189: iadd
     190: iload_0
     191: irem
     192: istore        7
     194: iload         10
     196: i2l
     197: iload         5
     199: iconst_1
     200: iadd
     201: i2l
     202: iload         6
     204: iload         4
     206: isub
     207: iload_0
     208: iadd
     209: i2l
     210: lmul
     211: ladd
     212: iload_0
     213: i2l
     214: lrem
     215: l2i
     216: istore        10
     218: iload         8
     220: iload         5
     222: iadd
     223: iconst_1
     224: iadd
     225: iload_0
     226: irem
     227: istore        8
     229: iload         9
     231: i2l
     232: iload         6
     234: i2l
     235: ladd
     236: iload         4
     238: i2l
     239: lsub
     240: iload_0
     241: i2l
     242: ladd
     243: iload_0
     244: i2l
     245: lrem
     246: l2i
     247: istore        9
     249: iload         5
     251: iload         6
     253: iadd
     254: iload_0
     255: irem
     256: istore        5
     258: iconst_2
     259: iload         6
     261: imul
     262: iload_0
     263: irem
     264: istore        6
     266: goto          391
     269: iload_2
     270: ifne          306
     273: aload_1
     274: iload         11
     276: invokevirtual #22                 // Method java/lang/String.charAt:(I)C
     279: istore_2
     280: aload_1
     281: iload         11
     283: invokevirtual #22                 // Method java/lang/String.charAt:(I)C
     286: istore_3
     287: iload         6
     289: istore        4
     291: iload         6
     293: istore        5
     295: iload         6
     297: iconst_1
     298: iadd
     299: iload_0
     300: irem
     301: istore        6
     303: goto          391
     306: iload         9
     308: iload         7
     310: iadd
     311: iload_0
     312: irem
     313: istore        9
     315: iload         10
     317: iload         8
     319: iadd
     320: iload_0
     321: irem
     322: istore        10
     324: aload_1
     325: iload         11
     327: invokevirtual #22                 // Method java/lang/String.charAt:(I)C
     330: iload_3
     331: if_icmpeq     372
     334: iload         8
     336: iload         5
     338: iadd
     339: iconst_1
     340: iadd
     341: iload_0
     342: irem
     343: istore        8
     345: iload         9
     347: iconst_1
     348: iadd
     349: iload_0
     350: irem
     351: istore        9
     353: iload         10
     355: iload         5
     357: iadd
     358: iconst_1
     359: iadd
     360: iload_0
     361: irem
     362: istore        10
     364: iload         7
     366: iconst_1
     367: iadd
     368: iload_0
     369: irem
     370: istore        7
     372: iload         6
     374: istore        5
     376: aload_1
     377: iload         11
     379: invokevirtual #22                 // Method java/lang/String.charAt:(I)C
     382: istore_3
     383: iload         6
     385: iconst_1
     386: iadd
     387: iload_0
     388: irem
     389: istore        6
     391: iinc          11, 1
     394: goto          47
     397: iload         10
     399: ireturn

  static int solve$default(int, int, java.lang.Object);
    Code:
       0: iload_1
       1: iconst_1
       2: iand
       3: ifeq          9
       6: ldc           #40                 // int 1000000007
       8: istore_0
       9: iload_0
      10: invokestatic  #42                 // Method solve:(I)I
      13: ireturn

  public static final void main();
    Code:
       0: invokestatic  #47                 // Method readInt:()I
       3: istore_0
       4: iconst_0
       5: istore_1
       6: iload_1
       7: iload_0
       8: if_icmpge     64
      11: iload_1
      12: istore_2
      13: iconst_0
      14: istore_3
      15: new           #49                 // class java/lang/StringBuilder
      18: dup
      19: invokespecial #52                 // Method java/lang/StringBuilder."<init>":()V
      22: ldc           #54                 // String Case #
      24: invokevirtual #58                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      27: iload_2
      28: iconst_1
      29: iadd
      30: invokevirtual #61                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      33: ldc           #63                 // String :
      35: invokevirtual #58                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      38: iconst_0
      39: iconst_1
      40: aconst_null
      41: invokestatic  #65                 // Method solve$default:(IILjava/lang/Object;)I
      44: invokevirtual #61                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      47: invokevirtual #68                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      50: getstatic     #74                 // Field java/lang/System.out:Ljava/io/PrintStream;
      53: swap
      54: invokevirtual #80                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      57: nop
      58: iinc          1, 1
      61: goto          6
      64: return

  private static final java.lang.String readLn();
    Code:
       0: invokestatic  #87                 // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
       3: dup
       4: invokestatic  #92                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
       7: areturn

  private static final int readInt();
    Code:
       0: invokestatic  #10                 // Method readLn:()Ljava/lang/String;
       3: invokestatic  #98                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
       6: ireturn

  public static void main(java.lang.String[]);
    Code:
       0: invokestatic  #101                // Method main:()V
       3: return
}


package facebook.y2020.qual

private fun solve(): Long {
	val (n, m) = readInts()
	val c = List(n) { readInt() }
	val a = mutableListOf(m to 0L)
	var low = 0
	val inf = c.fold(0L, Long::plus) + 1
	for (i in c.indices) {
		while (a[low].first < i) low++
		val cost = a[low].second
		if (i == n - 1) return cost.takeIf { it < inf } ?: -1L
		val costI = if (i == 0) 0L else c[i].toLong().takeIf { it > 0 } ?: inf
		val new = i + m to cost + costI
		while ((low < a.size) && (a.last().second >= new.second)) a.pop()
		a.add(new)
	}
	error("")
}

fun main() = repeat(readInt()) { println("Case #${it + 1}: ${solve()}") }

private fun <T> MutableList<T>.pop() = removeAt(lastIndex)
private fun readLn() = readLine()!!
private fun readInt() = readLn().toInt()
private fun readStrings() = readLn().split(" ")
private fun readInts() = readStrings().map { it.toInt() }

Compiled from "d1.kt"
public final class facebook.y2020.qual.D1Kt {
  private static final long solve();
    Code:
       0: invokestatic  #10                 // Method readInts:()Ljava/util/List;
       3: astore_0
       4: aload_0
       5: iconst_0
       6: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      11: checkcast     #18                 // class java/lang/Number
      14: invokevirtual #22                 // Method java/lang/Number.intValue:()I
      17: istore_1
      18: aload_0
      19: iconst_1
      20: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      25: checkcast     #18                 // class java/lang/Number
      28: invokevirtual #22                 // Method java/lang/Number.intValue:()I
      31: istore_2
      32: new           #24                 // class java/util/ArrayList
      35: dup
      36: iload_1
      37: invokespecial #28                 // Method java/util/ArrayList."<init>":(I)V
      40: astore        4
      42: iconst_0
      43: istore        5
      45: iload         5
      47: iload_1
      48: if_icmpge     85
      51: iload         5
      53: istore        6
      55: aload         4
      57: iload         6
      59: istore        7
      61: astore        21
      63: iconst_0
      64: istore        8
      66: invokestatic  #31                 // Method readInt:()I
      69: invokestatic  #37                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      72: aload         21
      74: swap
      75: invokevirtual #41                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
      78: pop
      79: iinc          5, 1
      82: goto          45
      85: aload         4
      87: checkcast     #12                 // class java/util/List
      90: astore_3
      91: iconst_1
      92: anewarray     #43                 // class kotlin/Pair
      95: astore        5
      97: aload         5
      99: iconst_0
     100: iload_2
     101: invokestatic  #37                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     104: lconst_0
     105: invokestatic  #48                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     108: invokestatic  #54                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     111: aastore
     112: aload         5
     114: invokestatic  #60                 // Method kotlin/collections/CollectionsKt.mutableListOf:([Ljava/lang/Object;)Ljava/util/List;
     117: astore        4
     119: iconst_0
     120: istore        5
     122: aload_3
     123: checkcast     #62                 // class java/lang/Iterable
     126: astore        8
     128: lconst_0
     129: lstore        9
     131: iconst_0
     132: istore        11
     134: lload         9
     136: lstore        12
     138: aload         8
     140: invokeinterface #66,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     145: astore        14
     147: aload         14
     149: invokeinterface #72,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     154: ifeq          194
     157: aload         14
     159: invokeinterface #76,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     164: astore        15
     166: lload         12
     168: aload         15
     170: checkcast     #18                 // class java/lang/Number
     173: invokevirtual #22                 // Method java/lang/Number.intValue:()I
     176: istore        16
     178: lstore        17
     180: iconst_0
     181: istore        19
     183: lload         17
     185: iload         16
     187: i2l
     188: ladd
     189: lstore        12
     191: goto          147
     194: lload         12
     196: lconst_1
     197: ladd
     198: lstore        6
     200: iconst_0
     201: istore        8
     203: aload_3
     204: checkcast     #78                 // class java/util/Collection
     207: invokeinterface #81,  1           // InterfaceMethod java/util/Collection.size:()I
     212: istore        9
     214: iload         8
     216: iload         9
     218: if_icmpge     508
     221: aload         4
     223: iload         5
     225: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     230: checkcast     #43                 // class kotlin/Pair
     233: invokevirtual #84                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     236: checkcast     #18                 // class java/lang/Number
     239: invokevirtual #22                 // Method java/lang/Number.intValue:()I
     242: iload         8
     244: if_icmpge     253
     247: iinc          5, 1
     250: goto          221
     253: aload         4
     255: iload         5
     257: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     262: checkcast     #43                 // class kotlin/Pair
     265: invokevirtual #87                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     268: checkcast     #18                 // class java/lang/Number
     271: invokevirtual #90                 // Method java/lang/Number.longValue:()J
     274: lstore        11
     276: iload         8
     278: iload_1
     279: iconst_1
     280: isub
     281: if_icmpne     341
     284: lload         11
     286: invokestatic  #48                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     289: astore        15
     291: aload         15
     293: checkcast     #18                 // class java/lang/Number
     296: invokevirtual #90                 // Method java/lang/Number.longValue:()J
     299: lstore        16
     301: iconst_0
     302: istore        18
     304: lload         16
     306: lload         6
     308: lcmp
     309: ifge          316
     312: iconst_1
     313: goto          317
     316: iconst_0
     317: ifeq          325
     320: aload         15
     322: goto          326
     325: aconst_null
     326: dup
     327: ifnull        336
     330: invokevirtual #91                 // Method java/lang/Long.longValue:()J
     333: goto          340
     336: pop
     337: ldc2_w        #92                 // long -1l
     340: lreturn
     341: iload         8
     343: ifne          350
     346: lconst_0
     347: goto          417
     350: aload_3
     351: iload         8
     353: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     358: checkcast     #18                 // class java/lang/Number
     361: invokevirtual #22                 // Method java/lang/Number.intValue:()I
     364: i2l
     365: invokestatic  #48                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     368: astore        17
     370: aload         17
     372: checkcast     #18                 // class java/lang/Number
     375: invokevirtual #90                 // Method java/lang/Number.longValue:()J
     378: lstore        18
     380: iconst_0
     381: istore        20
     383: lload         18
     385: lconst_0
     386: lcmp
     387: ifle          394
     390: iconst_1
     391: goto          395
     394: iconst_0
     395: ifeq          403
     398: aload         17
     400: goto          404
     403: aconst_null
     404: dup
     405: ifnull        414
     408: invokevirtual #91                 // Method java/lang/Long.longValue:()J
     411: goto          417
     414: pop
     415: lload         6
     417: lstore        14
     419: iload         8
     421: iload_2
     422: iadd
     423: invokestatic  #37                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     426: lload         11
     428: lload         14
     430: ladd
     431: invokestatic  #48                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     434: invokestatic  #54                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     437: astore        16
     439: iload         5
     441: aload         4
     443: invokeinterface #94,  1           // InterfaceMethod java/util/List.size:()I
     448: if_icmpge     492
     451: aload         4
     453: invokestatic  #98                 // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     456: checkcast     #43                 // class kotlin/Pair
     459: invokevirtual #87                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     462: checkcast     #18                 // class java/lang/Number
     465: invokevirtual #90                 // Method java/lang/Number.longValue:()J
     468: aload         16
     470: invokevirtual #87                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     473: checkcast     #18                 // class java/lang/Number
     476: invokevirtual #90                 // Method java/lang/Number.longValue:()J
     479: lcmp
     480: iflt          492
     483: aload         4
     485: invokestatic  #101                // Method pop:(Ljava/util/List;)Ljava/lang/Object;
     488: pop
     489: goto          439
     492: aload         4
     494: aload         16
     496: invokeinterface #102,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     501: pop
     502: iinc          8, 1
     505: goto          214
     508: new           #104                // class java/lang/IllegalStateException
     511: dup
     512: ldc           #106                // String
     514: invokevirtual #110                // Method java/lang/Object.toString:()Ljava/lang/String;
     517: invokespecial #113                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     520: athrow

  public static final void main();
    Code:
       0: invokestatic  #31                 // Method readInt:()I
       3: istore_0
       4: iconst_0
       5: istore_1
       6: iload_1
       7: iload_0
       8: if_icmpge     61
      11: iload_1
      12: istore_2
      13: iconst_0
      14: istore_3
      15: new           #145                // class java/lang/StringBuilder
      18: dup
      19: invokespecial #147                // Method java/lang/StringBuilder."<init>":()V
      22: ldc           #149                // String Case #
      24: invokevirtual #153                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      27: iload_2
      28: iconst_1
      29: iadd
      30: invokevirtual #156                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      33: ldc           #158                // String :
      35: invokevirtual #153                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      38: invokestatic  #160                // Method solve:()J
      41: invokevirtual #163                // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
      44: invokevirtual #164                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      47: getstatic     #170                // Field java/lang/System.out:Ljava/io/PrintStream;
      50: swap
      51: invokevirtual #176                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      54: nop
      55: iinc          1, 1
      58: goto          6
      61: return

  private static final <T> T pop(java.util.List<T>);
    Code:
       0: aload_0
       1: aload_0
       2: invokestatic  #182                // Method kotlin/collections/CollectionsKt.getLastIndex:(Ljava/util/List;)I
       5: invokeinterface #185,  2          // InterfaceMethod java/util/List.remove:(I)Ljava/lang/Object;
      10: areturn

  private static final java.lang.String readLn();
    Code:
       0: invokestatic  #192                // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
       3: dup
       4: invokestatic  #197                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
       7: areturn

  private static final int readInt();
    Code:
       0: invokestatic  #199                // Method readLn:()Ljava/lang/String;
       3: invokestatic  #203                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
       6: ireturn

  private static final java.util.List<java.lang.String> readStrings();
    Code:
       0: invokestatic  #199                // Method readLn:()Ljava/lang/String;
       3: checkcast     #207                // class java/lang/CharSequence
       6: iconst_1
       7: anewarray     #209                // class java/lang/String
      10: astore_0
      11: aload_0
      12: iconst_0
      13: ldc           #211                // String
      15: aastore
      16: aload_0
      17: iconst_0
      18: iconst_0
      19: bipush        6
      21: aconst_null
      22: invokestatic  #217                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      25: areturn

  private static final java.util.List<java.lang.Integer> readInts();
    Code:
       0: invokestatic  #220                // Method readStrings:()Ljava/util/List;
       3: checkcast     #62                 // class java/lang/Iterable
       6: astore_0
       7: iconst_0
       8: istore_1
       9: aload_0
      10: astore_2
      11: new           #24                 // class java/util/ArrayList
      14: dup
      15: aload_0
      16: bipush        10
      18: invokestatic  #224                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      21: invokespecial #28                 // Method java/util/ArrayList."<init>":(I)V
      24: checkcast     #78                 // class java/util/Collection
      27: astore_3
      28: iconst_0
      29: istore        4
      31: aload_2
      32: invokeinterface #66,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      37: astore        5
      39: aload         5
      41: invokeinterface #72,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      46: ifeq          92
      49: aload         5
      51: invokeinterface #76,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      56: astore        6
      58: aload_3
      59: aload         6
      61: checkcast     #209                // class java/lang/String
      64: astore        7
      66: astore        9
      68: iconst_0
      69: istore        8
      71: aload         7
      73: invokestatic  #203                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      76: nop
      77: invokestatic  #37                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      80: aload         9
      82: swap
      83: invokeinterface #225,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      88: pop
      89: goto          39
      92: aload_3
      93: checkcast     #12                 // class java/util/List
      96: nop
      97: areturn

  public static void main(java.lang.String[]);
    Code:
       0: invokestatic  #237                // Method main:()V
       3: return
}


package facebook.y2020.qual

private fun solve(): Int {
	val n = readInt()
	val growsHere = mutableMapOf<Int, Int>()
	val fallsHere = mutableMapOf<Int, MutableList<Int>>()
	repeat(n) {
		val (p, h) = readInts()
		growsHere[p] = h
		fallsHere.computeIfAbsent(p - h) { mutableListOf() }.add(h)
	}
	val best = mutableMapOf<Int, Int>()
	val bestWithoutThis = mutableMapOf<Int, Int>()
	for (x in (growsHere.keys + fallsHere.keys).sorted()) {
		val b = best.getOrDefault(x, 0)
		val bw = bestWithoutThis.getOrDefault(x, 0)
		for (h in fallsHere.getOrElse(x) { mutableListOf() }) {
			best[x + h] = maxOf(best.getOrDefault(x + h, 0), maxOf(b, bw) + h)
		}
		val h = growsHere[x] ?: continue
		bestWithoutThis[x + h] = maxOf(bestWithoutThis.getOrDefault(x + h, 0), bw + h)
	}
	return (best.values + bestWithoutThis.values).maxOrNull()!!
}

fun main() = repeat(readInt()) { println("Case #${it + 1}: ${solve()}") }

private fun readLn() = readLine()!!
private fun readInt() = readLn().toInt()
private fun readStrings() = readLn().split(" ")
private fun readInts() = readStrings().map { it.toInt() }

Compiled from "c.kt"
public final class facebook.y2020.qual.CKt {
  private static final int solve();
    Code:
       0: invokestatic  #9                  // Method readInt:()I
       3: istore_0
       4: new           #11                 // class java/util/LinkedHashMap
       7: dup
       8: invokespecial #15                 // Method java/util/LinkedHashMap."<init>":()V
      11: checkcast     #17                 // class java/util/Map
      14: astore_1
      15: new           #11                 // class java/util/LinkedHashMap
      18: dup
      19: invokespecial #15                 // Method java/util/LinkedHashMap."<init>":()V
      22: checkcast     #17                 // class java/util/Map
      25: astore_2
      26: iconst_0
      27: istore_3
      28: iload_3
      29: iload_0
      30: if_icmpge     146
      33: iload_3
      34: istore        4
      36: iconst_0
      37: istore        5
      39: invokestatic  #21                 // Method readInts:()Ljava/util/List;
      42: astore        6
      44: aload         6
      46: iconst_0
      47: invokeinterface #27,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      52: checkcast     #29                 // class java/lang/Number
      55: invokevirtual #32                 // Method java/lang/Number.intValue:()I
      58: istore        7
      60: aload         6
      62: iconst_1
      63: invokeinterface #27,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      68: checkcast     #29                 // class java/lang/Number
      71: invokevirtual #32                 // Method java/lang/Number.intValue:()I
      74: istore        8
      76: iload         7
      78: invokestatic  #38                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      81: astore        9
      83: iload         8
      85: invokestatic  #38                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      88: astore        10
      90: aload_1
      91: aload         9
      93: aload         10
      95: invokeinterface #42,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     100: pop
     101: aload_2
     102: iload         7
     104: iload         8
     106: isub
     107: invokestatic  #38                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     110: invokedynamic #61,  0             // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
     115: invokedynamic #72,  0             // InvokeDynamic #1:apply:(Lkotlin/jvm/functions/Function1;)Ljava/util/function/Function;
     120: invokeinterface #76,  3           // InterfaceMethod java/util/Map.computeIfAbsent:(Ljava/lang/Object;Ljava/util/function/Function;)Ljava/lang/Object;
     125: checkcast     #23                 // class java/util/List
     128: iload         8
     130: invokestatic  #38                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     133: invokeinterface #80,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     138: pop
     139: nop
     140: iinc          3, 1
     143: goto          28
     146: new           #11                 // class java/util/LinkedHashMap
     149: dup
     150: invokespecial #15                 // Method java/util/LinkedHashMap."<init>":()V
     153: checkcast     #17                 // class java/util/Map
     156: astore_3
     157: new           #11                 // class java/util/LinkedHashMap
     160: dup
     161: invokespecial #15                 // Method java/util/LinkedHashMap."<init>":()V
     164: checkcast     #17                 // class java/util/Map
     167: astore        4
     169: aload_1
     170: invokeinterface #84,  1           // InterfaceMethod java/util/Map.keySet:()Ljava/util/Set;
     175: aload_2
     176: invokeinterface #84,  1           // InterfaceMethod java/util/Map.keySet:()Ljava/util/Set;
     181: checkcast     #86                 // class java/lang/Iterable
     184: invokestatic  #92                 // Method kotlin/collections/SetsKt.plus:(Ljava/util/Set;Ljava/lang/Iterable;)Ljava/util/Set;
     187: checkcast     #86                 // class java/lang/Iterable
     190: invokestatic  #98                 // Method kotlin/collections/CollectionsKt.sorted:(Ljava/lang/Iterable;)Ljava/util/List;
     193: invokeinterface #102,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     198: astore        5
     200: aload         5
     202: invokeinterface #108,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     207: ifeq          487
     210: aload         5
     212: invokeinterface #112,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     217: checkcast     #29                 // class java/lang/Number
     220: invokevirtual #32                 // Method java/lang/Number.intValue:()I
     223: istore        6
     225: aload_3
     226: iload         6
     228: invokestatic  #38                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     231: iconst_0
     232: invokestatic  #38                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     235: invokeinterface #115,  3          // InterfaceMethod java/util/Map.getOrDefault:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     240: checkcast     #29                 // class java/lang/Number
     243: invokevirtual #32                 // Method java/lang/Number.intValue:()I
     246: istore        7
     248: aload         4
     250: iload         6
     252: invokestatic  #38                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     255: iconst_0
     256: invokestatic  #38                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     259: invokeinterface #115,  3          // InterfaceMethod java/util/Map.getOrDefault:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     264: checkcast     #29                 // class java/lang/Number
     267: invokevirtual #32                 // Method java/lang/Number.intValue:()I
     270: istore        8
     272: aload_2
     273: astore        10
     275: iload         6
     277: invokestatic  #38                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     280: aload         10
     282: swap
     283: invokeinterface #117,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     288: dup
     289: ifnonnull     307
     292: pop
     293: iconst_0
     294: istore        11
     296: new           #119                // class java/util/ArrayList
     299: dup
     300: invokespecial #120                // Method java/util/ArrayList."<init>":()V
     303: checkcast     #23                 // class java/util/List
     306: nop
     307: checkcast     #23                 // class java/util/List
     310: invokeinterface #102,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     315: astore        9
     317: aload         9
     319: invokeinterface #108,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     324: ifeq          401
     327: aload         9
     329: invokeinterface #112,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     334: checkcast     #29                 // class java/lang/Number
     337: invokevirtual #32                 // Method java/lang/Number.intValue:()I
     340: istore        10
     342: nop
     343: aload_3
     344: iload         6
     346: iload         10
     348: iadd
     349: invokestatic  #38                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     352: aload_3
     353: iload         6
     355: iload         10
     357: iadd
     358: invokestatic  #38                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     361: iconst_0
     362: invokestatic  #38                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     365: invokeinterface #115,  3          // InterfaceMethod java/util/Map.getOrDefault:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     370: checkcast     #29                 // class java/lang/Number
     373: invokevirtual #32                 // Method java/lang/Number.intValue:()I
     376: iload         7
     378: iload         8
     380: invokestatic  #126                // Method java/lang/Math.max:(II)I
     383: iload         10
     385: iadd
     386: invokestatic  #126                // Method java/lang/Math.max:(II)I
     389: invokestatic  #38                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     392: invokeinterface #42,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     397: pop
     398: goto          317
     401: aload_1
     402: iload         6
     404: invokestatic  #38                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     407: invokeinterface #117,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     412: checkcast     #34                 // class java/lang/Integer
     415: dup
     416: ifnull        425
     419: invokevirtual #127                // Method java/lang/Integer.intValue:()I
     422: goto          429
     425: pop
     426: goto          200
     429: istore        9
     431: nop
     432: aload         4
     434: iload         6
     436: iload         9
     438: iadd
     439: invokestatic  #38                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     442: aload         4
     444: iload         6
     446: iload         9
     448: iadd
     449: invokestatic  #38                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     452: iconst_0
     453: invokestatic  #38                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     456: invokeinterface #115,  3          // InterfaceMethod java/util/Map.getOrDefault:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     461: checkcast     #29                 // class java/lang/Number
     464: invokevirtual #32                 // Method java/lang/Number.intValue:()I
     467: iload         8
     469: iload         9
     471: iadd
     472: invokestatic  #126                // Method java/lang/Math.max:(II)I
     475: invokestatic  #38                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     478: invokeinterface #42,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     483: pop
     484: goto          200
     487: aload_3
     488: invokeinterface #131,  1          // InterfaceMethod java/util/Map.values:()Ljava/util/Collection;
     493: aload         4
     495: invokeinterface #131,  1          // InterfaceMethod java/util/Map.values:()Ljava/util/Collection;
     500: checkcast     #86                 // class java/lang/Iterable
     503: invokestatic  #134                // Method kotlin/collections/CollectionsKt.plus:(Ljava/util/Collection;Ljava/lang/Iterable;)Ljava/util/List;
     506: checkcast     #86                 // class java/lang/Iterable
     509: invokestatic  #138                // Method kotlin/collections/CollectionsKt.maxOrNull:(Ljava/lang/Iterable;)Ljava/lang/Comparable;
     512: dup
     513: invokestatic  #144                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     516: checkcast     #29                 // class java/lang/Number
     519: invokevirtual #32                 // Method java/lang/Number.intValue:()I
     522: ireturn

  public static final void main();
    Code:
       0: invokestatic  #9                  // Method readInt:()I
       3: istore_0
       4: iconst_0
       5: istore_1
       6: iload_1
       7: iload_0
       8: if_icmpge     61
      11: iload_1
      12: istore_2
      13: iconst_0
      14: istore_3
      15: new           #162                // class java/lang/StringBuilder
      18: dup
      19: invokespecial #163                // Method java/lang/StringBuilder."<init>":()V
      22: ldc           #165                // String Case #
      24: invokevirtual #169                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      27: iload_2
      28: iconst_1
      29: iadd
      30: invokevirtual #172                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      33: ldc           #174                // String :
      35: invokevirtual #169                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      38: invokestatic  #176                // Method solve:()I
      41: invokevirtual #172                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      44: invokevirtual #180                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      47: getstatic     #186                // Field java/lang/System.out:Ljava/io/PrintStream;
      50: swap
      51: invokevirtual #191                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      54: nop
      55: iinc          1, 1
      58: goto          6
      61: return

  private static final java.lang.String readLn();
    Code:
       0: invokestatic  #198                // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
       3: dup
       4: invokestatic  #144                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
       7: areturn

  private static final int readInt();
    Code:
       0: invokestatic  #200                // Method readLn:()Ljava/lang/String;
       3: invokestatic  #204                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
       6: ireturn

  private static final java.util.List<java.lang.String> readStrings();
    Code:
       0: invokestatic  #200                // Method readLn:()Ljava/lang/String;
       3: checkcast     #208                // class java/lang/CharSequence
       6: iconst_1
       7: anewarray     #210                // class java/lang/String
      10: astore_0
      11: aload_0
      12: iconst_0
      13: ldc           #212                // String
      15: aastore
      16: aload_0
      17: iconst_0
      18: iconst_0
      19: bipush        6
      21: aconst_null
      22: invokestatic  #218                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      25: areturn

  private static final java.util.List<java.lang.Integer> readInts();
    Code:
       0: invokestatic  #221                // Method readStrings:()Ljava/util/List;
       3: checkcast     #86                 // class java/lang/Iterable
       6: astore_0
       7: iconst_0
       8: istore_1
       9: aload_0
      10: astore_2
      11: new           #119                // class java/util/ArrayList
      14: dup
      15: aload_0
      16: bipush        10
      18: invokestatic  #225                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      21: invokespecial #228                // Method java/util/ArrayList."<init>":(I)V
      24: checkcast     #230                // class java/util/Collection
      27: astore_3
      28: iconst_0
      29: istore        4
      31: aload_2
      32: invokeinterface #231,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      37: astore        5
      39: aload         5
      41: invokeinterface #108,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      46: ifeq          92
      49: aload         5
      51: invokeinterface #112,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      56: astore        6
      58: aload_3
      59: aload         6
      61: checkcast     #210                // class java/lang/String
      64: astore        7
      66: astore        9
      68: iconst_0
      69: istore        8
      71: aload         7
      73: invokestatic  #204                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      76: nop
      77: invokestatic  #38                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      80: aload         9
      82: swap
      83: invokeinterface #232,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      88: pop
      89: goto          39
      92: aload_3
      93: checkcast     #23                 // class java/util/List
      96: nop
      97: areturn

  public static void main(java.lang.String[]);
    Code:
       0: invokestatic  #246                // Method main:()V
       3: return

  private static final java.util.List solve$lambda$2$lambda$0(java.lang.Integer);
    Code:
       0: aload_0
       1: ldc           #249                // String it
       3: invokestatic  #253                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #119                // class java/util/ArrayList
       9: dup
      10: invokespecial #120                // Method java/util/ArrayList."<init>":()V
      13: checkcast     #23                 // class java/util/List
      16: areturn

  private static final java.util.List solve$lambda$2$lambda$1(kotlin.jvm.functions.Function1, java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: invokeinterface #258,  2          // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
       7: checkcast     #23                 // class java/util/List
      10: areturn
}