package facebook.y2020.round2

import java.util.*

private fun solve(MOD: Int = 1_000_000_007, maxWeight: Int = 1_000_000_000): Int {
	val (n, m, events, k) = readInts()
	val edges = n * m + n
	val (x, y, ids, weights) = listOf(m to n, m to n, edges to events, maxWeight to events).map { (modulo, length) ->
		val array = readInts().toIntArray() + IntArray(length - k) { 0 }
		val (a, b, c) = readInts()
		for (i in k until length) {
			array[i] = ((a.toLong() * array[i - 2] + b.toLong() * array[i - 1] + c) % modulo).toInt()
		}
		array
	}
	val (short, long) = List(2) { List(n) { TreeSet<Long>() } }
	val main = TreeSet<Long>()
	val alter = LongArray(n) { -1L }
	val selected = LongArray(n) { -1L }
	fun isShort(cycle: Int, j: Int): Boolean {
		return x[cycle] <= j && j < y[cycle]
	}
	for (cycle in x.indices) {
		val (min, max) = listOf(x[cycle], y[cycle]).sorted()
		x[cycle] = min; y[cycle] = max
		for (j in 0 until m) {
			val id = cycle * m + j
			if (isShort(cycle, j)) {
				short[cycle].add(1L * edges + id)
			} else {
				long[cycle].add(1L * edges + id)
			}
		}
		if (short[cycle].isNotEmpty()) {
			alter[cycle] = short[cycle].last()
			main.add(alter[cycle])
		}
		selected[cycle] = long[cycle].last()
		main.add(1L * edges + n * m + cycle)
	}
	var ans = 1
	val w = IntArray(edges) { 1 }
	var sum = edges.toLong()
	var removed = (n + 1).toLong()
	for (event in ids.indices) {
		val id = ids[event]
		val oldWeight = w[id]
		val newWeight = weights[event]
		removed -= main.last() / edges
		if (id < n * m) {
			val cycle = id / m
			val j = id % m
			val set = if (isShort(cycle, j)) short[cycle] else long[cycle]
			if (!set.remove(oldWeight.toLong() * edges + id)) error("")
			set.add(newWeight.toLong() * edges + id)
			val alt = alter[cycle]
			val sel = selected[cycle]
			removed -= sel / edges
			if (alt != -1L) {
				if (!main.remove(alt)) error("")
				val a1 = short[cycle].last()
				val a2 = long[cycle].last()
				alter[cycle] = minOf(a1, a2)
				main.add(alter[cycle])
				selected[cycle] = maxOf(a1, a2)
			} else {
				selected[cycle] = long[cycle].last()
			}
			removed += selected[cycle] / edges
		} else {
			main.remove(oldWeight.toLong() * edges + id)
			main.add(newWeight.toLong() * edges + id)
		}
		removed += main.last() / edges
		sum += newWeight - oldWeight
		w[id] = newWeight
		ans = ((ans * ((sum - removed) % MOD)) % MOD).toInt()
	}
	return ans
}

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.round2.CKt {
  private static final int solve(int, int);
    Code:
       0: invokestatic  #10                 // Method readInts:()Ljava/util/List;
       3: astore_2
       4: aload_2
       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_3
      18: aload_2
      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        4
      33: aload_2
      34: iconst_2
      35: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      40: checkcast     #18                 // class java/lang/Number
      43: invokevirtual #22                 // Method java/lang/Number.intValue:()I
      46: istore        5
      48: aload_2
      49: iconst_3
      50: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      55: checkcast     #18                 // class java/lang/Number
      58: invokevirtual #22                 // Method java/lang/Number.intValue:()I
      61: istore        6
      63: iload_3
      64: iload         4
      66: imul
      67: iload_3
      68: iadd
      69: istore        7
      71: iconst_4
      72: anewarray     #24                 // class kotlin/Pair
      75: astore        9
      77: aload         9
      79: iconst_0
      80: iload         4
      82: invokestatic  #30                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      85: iload_3
      86: invokestatic  #30                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      89: invokestatic  #36                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      92: aastore
      93: aload         9
      95: iconst_1
      96: iload         4
      98: invokestatic  #30                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     101: iload_3
     102: invokestatic  #30                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     105: invokestatic  #36                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     108: aastore
     109: aload         9
     111: iconst_2
     112: iload         7
     114: invokestatic  #30                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     117: iload         5
     119: invokestatic  #30                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     122: invokestatic  #36                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     125: aastore
     126: aload         9
     128: iconst_3
     129: iload_1
     130: invokestatic  #30                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     133: iload         5
     135: invokestatic  #30                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     138: invokestatic  #36                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     141: aastore
     142: aload         9
     144: invokestatic  #42                 // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     147: checkcast     #44                 // class java/lang/Iterable
     150: astore        9
     152: iconst_0
     153: istore        10
     155: aload         9
     157: astore        11
     159: new           #46                 // class java/util/ArrayList
     162: dup
     163: aload         9
     165: bipush        10
     167: invokestatic  #50                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     170: invokespecial #54                 // Method java/util/ArrayList."<init>":(I)V
     173: checkcast     #56                 // class java/util/Collection
     176: astore        12
     178: iconst_0
     179: istore        13
     181: aload         11
     183: invokeinterface #60,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     188: astore        14
     190: aload         14
     192: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     197: ifeq          431
     200: aload         14
     202: invokeinterface #70,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     207: astore        15
     209: aload         12
     211: aload         15
     213: checkcast     #24                 // class kotlin/Pair
     216: astore        16
     218: astore        39
     220: iconst_0
     221: istore        17
     223: aload         16
     225: invokevirtual #73                 // Method kotlin/Pair.component1:()Ljava/lang/Object;
     228: checkcast     #18                 // class java/lang/Number
     231: invokevirtual #22                 // Method java/lang/Number.intValue:()I
     234: istore        18
     236: aload         16
     238: invokevirtual #76                 // Method kotlin/Pair.component2:()Ljava/lang/Object;
     241: checkcast     #18                 // class java/lang/Number
     244: invokevirtual #22                 // Method java/lang/Number.intValue:()I
     247: istore        19
     249: invokestatic  #10                 // Method readInts:()Ljava/util/List;
     252: checkcast     #56                 // class java/util/Collection
     255: invokestatic  #80                 // Method kotlin/collections/CollectionsKt.toIntArray:(Ljava/util/Collection;)[I
     258: iconst_0
     259: istore        20
     261: iload         19
     263: iload         6
     265: isub
     266: istore        21
     268: iload         21
     270: newarray       int
     272: astore        22
     274: astore        23
     276: iload         20
     278: iload         21
     280: if_icmpge     299
     283: iload         20
     285: istore        24
     287: aload         22
     289: iload         24
     291: iconst_0
     292: iastore
     293: iinc          20, 1
     296: goto          276
     299: aload         23
     301: aload         22
     303: invokestatic  #86                 // Method kotlin/collections/ArraysKt.plus:([I[I)[I
     306: astore        25
     308: invokestatic  #10                 // Method readInts:()Ljava/util/List;
     311: astore        20
     313: aload         20
     315: iconst_0
     316: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     321: checkcast     #18                 // class java/lang/Number
     324: invokevirtual #22                 // Method java/lang/Number.intValue:()I
     327: istore        21
     329: aload         20
     331: iconst_1
     332: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     337: checkcast     #18                 // class java/lang/Number
     340: invokevirtual #22                 // Method java/lang/Number.intValue:()I
     343: istore        22
     345: aload         20
     347: iconst_2
     348: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     353: checkcast     #18                 // class java/lang/Number
     356: invokevirtual #22                 // Method java/lang/Number.intValue:()I
     359: istore        24
     361: iload         6
     363: istore        26
     365: iload         26
     367: iload         19
     369: if_icmpge     417
     372: aload         25
     374: iload         26
     376: iload         21
     378: i2l
     379: aload         25
     381: iload         26
     383: iconst_2
     384: isub
     385: iaload
     386: i2l
     387: lmul
     388: iload         22
     390: i2l
     391: aload         25
     393: iload         26
     395: iconst_1
     396: isub
     397: iaload
     398: i2l
     399: lmul
     400: ladd
     401: iload         24
     403: i2l
     404: ladd
     405: iload         18
     407: i2l
     408: lrem
     409: l2i
     410: iastore
     411: iinc          26, 1
     414: goto          365
     417: aload         25
     419: aload         39
     421: swap
     422: invokeinterface #90,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     427: pop
     428: goto          190
     431: aload         12
     433: checkcast     #12                 // class java/util/List
     436: nop
     437: astore        8
     439: aload         8
     441: iconst_0
     442: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     447: checkcast     #92                 // class "[I"
     450: astore        9
     452: aload         8
     454: iconst_1
     455: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     460: checkcast     #92                 // class "[I"
     463: astore        10
     465: aload         8
     467: iconst_2
     468: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     473: checkcast     #92                 // class "[I"
     476: astore        11
     478: aload         8
     480: iconst_3
     481: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     486: checkcast     #92                 // class "[I"
     489: astore        12
     491: iconst_2
     492: istore        14
     494: new           #46                 // class java/util/ArrayList
     497: dup
     498: iload         14
     500: invokespecial #54                 // Method java/util/ArrayList."<init>":(I)V
     503: astore        15
     505: iconst_0
     506: istore        16
     508: iload         16
     510: iload         14
     512: if_icmpge     603
     515: iload         16
     517: istore        17
     519: aload         15
     521: iload         17
     523: istore        18
     525: astore        39
     527: iconst_0
     528: istore        19
     530: new           #46                 // class java/util/ArrayList
     533: dup
     534: iload_3
     535: invokespecial #54                 // Method java/util/ArrayList."<init>":(I)V
     538: astore        20
     540: iconst_0
     541: istore        21
     543: iload         21
     545: iload_3
     546: if_icmpge     584
     549: iload         21
     551: istore        22
     553: aload         20
     555: iload         22
     557: istore        23
     559: astore        24
     561: iconst_0
     562: istore        25
     564: new           #94                 // class java/util/TreeSet
     567: dup
     568: invokespecial #97                 // Method java/util/TreeSet."<init>":()V
     571: aload         24
     573: swap
     574: invokevirtual #98                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     577: pop
     578: iinc          21, 1
     581: goto          543
     584: aload         20
     586: checkcast     #12                 // class java/util/List
     589: nop
     590: aload         39
     592: swap
     593: invokevirtual #98                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     596: pop
     597: iinc          16, 1
     600: goto          508
     603: aload         15
     605: checkcast     #12                 // class java/util/List
     608: astore        13
     610: aload         13
     612: iconst_0
     613: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     618: checkcast     #12                 // class java/util/List
     621: astore        14
     623: aload         13
     625: iconst_1
     626: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     631: checkcast     #12                 // class java/util/List
     634: astore        15
     636: new           #94                 // class java/util/TreeSet
     639: dup
     640: invokespecial #97                 // Method java/util/TreeSet."<init>":()V
     643: astore        16
     645: iconst_0
     646: istore        18
     648: iload_3
     649: newarray       long
     651: astore        19
     653: iload         18
     655: iload_3
     656: if_icmpge     677
     659: iload         18
     661: istore        20
     663: aload         19
     665: iload         20
     667: ldc2_w        #99                 // long -1l
     670: lastore
     671: iinc          18, 1
     674: goto          653
     677: aload         19
     679: astore        17
     681: iconst_0
     682: istore        19
     684: iload_3
     685: newarray       long
     687: astore        20
     689: iload         19
     691: iload_3
     692: if_icmpge     713
     695: iload         19
     697: istore        21
     699: aload         20
     701: iload         21
     703: ldc2_w        #99                 // long -1l
     706: lastore
     707: iinc          19, 1
     710: goto          689
     713: aload         20
     715: astore        18
     717: iconst_0
     718: istore        19
     720: aload         9
     722: arraylength
     723: istore        20
     725: iload         19
     727: iload         20
     729: if_icmpge     1055
     732: iconst_2
     733: anewarray     #26                 // class java/lang/Integer
     736: astore        22
     738: aload         22
     740: iconst_0
     741: aload         9
     743: iload         19
     745: iaload
     746: invokestatic  #30                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     749: aastore
     750: aload         22
     752: iconst_1
     753: aload         10
     755: iload         19
     757: iaload
     758: invokestatic  #30                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     761: aastore
     762: aload         22
     764: invokestatic  #42                 // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     767: checkcast     #44                 // class java/lang/Iterable
     770: invokestatic  #104                // Method kotlin/collections/CollectionsKt.sorted:(Ljava/lang/Iterable;)Ljava/util/List;
     773: astore        21
     775: aload         21
     777: iconst_0
     778: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     783: checkcast     #18                 // class java/lang/Number
     786: invokevirtual #22                 // Method java/lang/Number.intValue:()I
     789: istore        22
     791: aload         21
     793: iconst_1
     794: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     799: checkcast     #18                 // class java/lang/Number
     802: invokevirtual #22                 // Method java/lang/Number.intValue:()I
     805: istore        23
     807: aload         9
     809: iload         19
     811: iload         22
     813: iastore
     814: aload         10
     816: iload         19
     818: iload         23
     820: iastore
     821: iconst_0
     822: istore        24
     824: iload         24
     826: iload         4
     828: if_icmpge     919
     831: iload         19
     833: iload         4
     835: imul
     836: iload         24
     838: iadd
     839: istore        25
     841: aload         9
     843: aload         10
     845: iload         19
     847: iload         24
     849: invokestatic  #108                // Method solve$isShort:([I[III)Z
     852: ifeq          885
     855: aload         14
     857: iload         19
     859: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     864: checkcast     #94                 // class java/util/TreeSet
     867: lconst_1
     868: iload         7
     870: i2l
     871: lmul
     872: iload         25
     874: i2l
     875: ladd
     876: invokestatic  #113                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     879: invokevirtual #114                // Method java/util/TreeSet.add:(Ljava/lang/Object;)Z
     882: goto          912
     885: aload         15
     887: iload         19
     889: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     894: checkcast     #94                 // class java/util/TreeSet
     897: lconst_1
     898: iload         7
     900: i2l
     901: lmul
     902: iload         25
     904: i2l
     905: ladd
     906: invokestatic  #113                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     909: invokevirtual #114                // Method java/util/TreeSet.add:(Ljava/lang/Object;)Z
     912: pop
     913: iinc          24, 1
     916: goto          824
     919: aload         14
     921: iload         19
     923: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     928: checkcast     #56                 // class java/util/Collection
     931: invokeinterface #117,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     936: ifne          943
     939: iconst_1
     940: goto          944
     943: iconst_0
     944: ifeq          993
     947: aload         17
     949: iload         19
     951: aload         14
     953: iload         19
     955: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     960: checkcast     #94                 // class java/util/TreeSet
     963: invokevirtual #120                // Method java/util/TreeSet.last:()Ljava/lang/Object;
     966: dup
     967: ldc           #122                // String last(...)
     969: invokestatic  #128                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     972: checkcast     #18                 // class java/lang/Number
     975: invokevirtual #132                // Method java/lang/Number.longValue:()J
     978: lastore
     979: aload         16
     981: aload         17
     983: iload         19
     985: laload
     986: invokestatic  #113                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     989: invokevirtual #114                // Method java/util/TreeSet.add:(Ljava/lang/Object;)Z
     992: pop
     993: aload         18
     995: iload         19
     997: aload         15
     999: iload         19
    1001: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
    1006: checkcast     #94                 // class java/util/TreeSet
    1009: invokevirtual #120                // Method java/util/TreeSet.last:()Ljava/lang/Object;
    1012: dup
    1013: ldc           #122                // String last(...)
    1015: invokestatic  #128                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
    1018: checkcast     #18                 // class java/lang/Number
    1021: invokevirtual #132                // Method java/lang/Number.longValue:()J
    1024: lastore
    1025: aload         16
    1027: lconst_1
    1028: iload         7
    1030: i2l
    1031: lmul
    1032: iload_3
    1033: iload         4
    1035: imul
    1036: i2l
    1037: ladd
    1038: iload         19
    1040: i2l
    1041: ladd
    1042: invokestatic  #113                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
    1045: invokevirtual #114                // Method java/util/TreeSet.add:(Ljava/lang/Object;)Z
    1048: pop
    1049: iinc          19, 1
    1052: goto          725
    1055: iconst_1
    1056: istore        19
    1058: iconst_0
    1059: istore        21
    1061: iload         7
    1063: newarray       int
    1065: astore        22
    1067: iload         21
    1069: iload         7
    1071: if_icmpge     1090
    1074: iload         21
    1076: istore        23
    1078: aload         22
    1080: iload         23
    1082: iconst_1
    1083: iastore
    1084: iinc          21, 1
    1087: goto          1067
    1090: aload         22
    1092: astore        20
    1094: iload         7
    1096: i2l
    1097: lstore        21
    1099: iload_3
    1100: iconst_1
    1101: iadd
    1102: i2l
    1103: lstore        23
    1105: iconst_0
    1106: istore        25
    1108: aload         11
    1110: arraylength
    1111: istore        26
    1113: iload         25
    1115: iload         26
    1117: if_icmpge     1596
    1120: aload         11
    1122: iload         25
    1124: iaload
    1125: istore        27
    1127: aload         20
    1129: iload         27
    1131: iaload
    1132: istore        28
    1134: aload         12
    1136: iload         25
    1138: iaload
    1139: istore        29
    1141: lload         23
    1143: aload         16
    1145: invokevirtual #120                // Method java/util/TreeSet.last:()Ljava/lang/Object;
    1148: checkcast     #18                 // class java/lang/Number
    1151: invokevirtual #132                // Method java/lang/Number.longValue:()J
    1154: iload         7
    1156: i2l
    1157: ldiv
    1158: lsub
    1159: lstore        23
    1161: iload         27
    1163: iload_3
    1164: iload         4
    1166: imul
    1167: if_icmpge     1494
    1170: iload         27
    1172: iload         4
    1174: idiv
    1175: istore        30
    1177: iload         27
    1179: iload         4
    1181: irem
    1182: istore        31
    1184: aload         9
    1186: aload         10
    1188: iload         30
    1190: iload         31
    1192: invokestatic  #108                // Method solve$isShort:([I[III)Z
    1195: ifeq          1213
    1198: aload         14
    1200: iload         30
    1202: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
    1207: checkcast     #94                 // class java/util/TreeSet
    1210: goto          1225
    1213: aload         15
    1215: iload         30
    1217: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
    1222: checkcast     #94                 // class java/util/TreeSet
    1225: astore        32
    1227: aload         32
    1229: iload         28
    1231: i2l
    1232: iload         7
    1234: i2l
    1235: lmul
    1236: iload         27
    1238: i2l
    1239: ladd
    1240: invokestatic  #113                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
    1243: invokevirtual #135                // Method java/util/TreeSet.remove:(Ljava/lang/Object;)Z
    1246: ifne          1262
    1249: new           #137                // class java/lang/IllegalStateException
    1252: dup
    1253: ldc           #139                // String
    1255: invokevirtual #143                // Method java/lang/Object.toString:()Ljava/lang/String;
    1258: invokespecial #146                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
    1261: athrow
    1262: aload         32
    1264: iload         29
    1266: i2l
    1267: iload         7
    1269: i2l
    1270: lmul
    1271: iload         27
    1273: i2l
    1274: ladd
    1275: invokestatic  #113                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
    1278: invokevirtual #114                // Method java/util/TreeSet.add:(Ljava/lang/Object;)Z
    1281: pop
    1282: aload         17
    1284: iload         30
    1286: laload
    1287: lstore        33
    1289: aload         18
    1291: iload         30
    1293: laload
    1294: lstore        35
    1296: lload         23
    1298: lload         35
    1300: iload         7
    1302: i2l
    1303: ldiv
    1304: lsub
    1305: lstore        23
    1307: lload         33
    1309: ldc2_w        #99                 // long -1l
    1312: lcmp
    1313: ifeq          1445
    1316: aload         16
    1318: lload         33
    1320: invokestatic  #113                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
    1323: invokevirtual #135                // Method java/util/TreeSet.remove:(Ljava/lang/Object;)Z
    1326: ifne          1342
    1329: new           #137                // class java/lang/IllegalStateException
    1332: dup
    1333: ldc           #139                // String
    1335: invokevirtual #143                // Method java/lang/Object.toString:()Ljava/lang/String;
    1338: invokespecial #146                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
    1341: athrow
    1342: aload         14
    1344: iload         30
    1346: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
    1351: checkcast     #94                 // class java/util/TreeSet
    1354: invokevirtual #120                // Method java/util/TreeSet.last:()Ljava/lang/Object;
    1357: checkcast     #110                // class java/lang/Long
    1360: astore        37
    1362: aload         15
    1364: iload         30
    1366: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
    1371: checkcast     #94                 // class java/util/TreeSet
    1374: invokevirtual #120                // Method java/util/TreeSet.last:()Ljava/lang/Object;
    1377: checkcast     #110                // class java/lang/Long
    1380: astore        38
    1382: aload         17
    1384: iload         30
    1386: aload         37
    1388: invokestatic  #150                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
    1391: aload         37
    1393: invokevirtual #151                // Method java/lang/Long.longValue:()J
    1396: aload         38
    1398: invokestatic  #150                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
    1401: aload         38
    1403: invokevirtual #151                // Method java/lang/Long.longValue:()J
    1406: invokestatic  #157                // Method java/lang/Math.min:(JJ)J
    1409: lastore
    1410: aload         16
    1412: aload         17
    1414: iload         30
    1416: laload
    1417: invokestatic  #113                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
    1420: invokevirtual #114                // Method java/util/TreeSet.add:(Ljava/lang/Object;)Z
    1423: pop
    1424: aload         18
    1426: iload         30
    1428: aload         37
    1430: invokevirtual #151                // Method java/lang/Long.longValue:()J
    1433: aload         38
    1435: invokevirtual #151                // Method java/lang/Long.longValue:()J
    1438: invokestatic  #160                // Method java/lang/Math.max:(JJ)J
    1441: lastore
    1442: goto          1477
    1445: aload         18
    1447: iload         30
    1449: aload         15
    1451: iload         30
    1453: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
    1458: checkcast     #94                 // class java/util/TreeSet
    1461: invokevirtual #120                // Method java/util/TreeSet.last:()Ljava/lang/Object;
    1464: dup
    1465: ldc           #122                // String last(...)
    1467: invokestatic  #128                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
    1470: checkcast     #18                 // class java/lang/Number
    1473: invokevirtual #132                // Method java/lang/Number.longValue:()J
    1476: lastore
    1477: lload         23
    1479: aload         18
    1481: iload         30
    1483: laload
    1484: iload         7
    1486: i2l
    1487: ldiv
    1488: ladd
    1489: lstore        23
    1491: goto          1534
    1494: aload         16
    1496: iload         28
    1498: i2l
    1499: iload         7
    1501: i2l
    1502: lmul
    1503: iload         27
    1505: i2l
    1506: ladd
    1507: invokestatic  #113                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
    1510: invokevirtual #135                // Method java/util/TreeSet.remove:(Ljava/lang/Object;)Z
    1513: pop
    1514: aload         16
    1516: iload         29
    1518: i2l
    1519: iload         7
    1521: i2l
    1522: lmul
    1523: iload         27
    1525: i2l
    1526: ladd
    1527: invokestatic  #113                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
    1530: invokevirtual #114                // Method java/util/TreeSet.add:(Ljava/lang/Object;)Z
    1533: pop
    1534: lload         23
    1536: aload         16
    1538: invokevirtual #120                // Method java/util/TreeSet.last:()Ljava/lang/Object;
    1541: checkcast     #18                 // class java/lang/Number
    1544: invokevirtual #132                // Method java/lang/Number.longValue:()J
    1547: iload         7
    1549: i2l
    1550: ldiv
    1551: ladd
    1552: lstore        23
    1554: lload         21
    1556: iload         29
    1558: iload         28
    1560: isub
    1561: i2l
    1562: ladd
    1563: lstore        21
    1565: aload         20
    1567: iload         27
    1569: iload         29
    1571: iastore
    1572: iload         19
    1574: i2l
    1575: lload         21
    1577: lload         23
    1579: lsub
    1580: iload_0
    1581: i2l
    1582: lrem
    1583: lmul
    1584: iload_0
    1585: i2l
    1586: lrem
    1587: l2i
    1588: istore        19
    1590: iinc          25, 1
    1593: goto          1113
    1596: iload         19
    1598: ireturn

  static int solve$default(int, int, int, java.lang.Object);
    Code:
       0: iload_2
       1: iconst_1
       2: iand
       3: ifeq          9
       6: ldc           #221                // int 1000000007
       8: istore_0
       9: iload_2
      10: iconst_2
      11: iand
      12: ifeq          18
      15: ldc           #222                // int 1000000000
      17: istore_1
      18: iload_0
      19: iload_1
      20: invokestatic  #224                // Method solve:(II)I
      23: ireturn

  public static final void main();
    Code:
       0: invokestatic  #227                // 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           #229                // class java/lang/StringBuilder
      18: dup
      19: invokespecial #230                // Method java/lang/StringBuilder."<init>":()V
      22: ldc           #232                // String Case #
      24: invokevirtual #236                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      27: iload_2
      28: iconst_1
      29: iadd
      30: invokevirtual #239                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      33: ldc           #241                // String :
      35: invokevirtual #236                // 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  #243                // Method solve$default:(IIILjava/lang/Object;)I
      45: invokevirtual #239                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      48: invokevirtual #244                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      51: getstatic     #250                // Field java/lang/System.out:Ljava/io/PrintStream;
      54: swap
      55: invokevirtual #255                // 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  #262                // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
       3: dup
       4: invokestatic  #150                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
       7: areturn

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

  private static final java.util.List<java.lang.String> readStrings();
    Code:
       0: invokestatic  #264                // Method readLn:()Ljava/lang/String;
       3: checkcast     #272                // class java/lang/CharSequence
       6: iconst_1
       7: anewarray     #274                // class java/lang/String
      10: astore_0
      11: aload_0
      12: iconst_0
      13: ldc_w         #276                // String
      16: aastore
      17: aload_0
      18: iconst_0
      19: iconst_0
      20: bipush        6
      22: aconst_null
      23: invokestatic  #282                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      26: areturn

  private static final java.util.List<java.lang.Integer> readInts();
    Code:
       0: invokestatic  #285                // Method readStrings:()Ljava/util/List;
       3: checkcast     #44                 // class java/lang/Iterable
       6: astore_0
       7: iconst_0
       8: istore_1
       9: aload_0
      10: astore_2
      11: new           #46                 // class java/util/ArrayList
      14: dup
      15: aload_0
      16: bipush        10
      18: invokestatic  #50                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      21: invokespecial #54                 // Method java/util/ArrayList."<init>":(I)V
      24: checkcast     #56                 // class java/util/Collection
      27: astore_3
      28: iconst_0
      29: istore        4
      31: aload_2
      32: invokeinterface #60,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      37: astore        5
      39: aload         5
      41: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      46: ifeq          92
      49: aload         5
      51: invokeinterface #70,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      56: astore        6
      58: aload_3
      59: aload         6
      61: checkcast     #274                // class java/lang/String
      64: astore        7
      66: astore        9
      68: iconst_0
      69: istore        8
      71: aload         7
      73: invokestatic  #268                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      76: nop
      77: invokestatic  #30                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      80: aload         9
      82: swap
      83: invokeinterface #90,  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  #290                // Method main:()V
       3: return

  private static final boolean solve$isShort(int[], int[], int, int);
    Code:
       0: aload_0
       1: iload_2
       2: iaload
       3: iload_3
       4: if_icmpgt     18
       7: iload_3
       8: aload_1
       9: iload_2
      10: iaload
      11: if_icmpge     18
      14: iconst_1
      15: goto          19
      18: iconst_0
      19: ireturn
}


package facebook.y2020.round2

private fun solve(): Long {
	val (n, k) = readInts()
	val (s, x, y) = List(3) {
		val array = readInts().toIntArray() + IntArray(n - k) { 0 }
		val (a, b, c, d) = readInts()
		for (i in k until n) {
			array[i] = ((a.toLong() * array[i - 2] + b.toLong() * array[i - 1] + c) % d).toInt()
		}
		array
	}
	var up = 0L
	var down = 0L
	var canUp = 0L
	var canDown = 0L
	for (i in s.indices) {
		if (s[i] < x[i]) up += x[i] - s[i]
		canUp += maxOf(0, x[i] + y[i] - s[i])
		if (s[i] > x[i] + y[i]) down += s[i] - x[i] - y[i]
		canDown += maxOf(0, s[i] - x[i])
	}
	if (up > canDown || down > canUp) return -1L
	return maxOf(up, down)
}

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 "a.kt"
public final class facebook.y2020.round2.AKt {
  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: iconst_3
      33: istore        4
      35: new           #24                 // class java/util/ArrayList
      38: dup
      39: iload         4
      41: invokespecial #28                 // Method java/util/ArrayList."<init>":(I)V
      44: astore        5
      46: iconst_0
      47: istore        6
      49: iload         6
      51: iload         4
      53: if_icmpge     266
      56: iload         6
      58: istore        7
      60: aload         5
      62: iload         7
      64: istore        8
      66: astore        18
      68: iconst_0
      69: istore        9
      71: invokestatic  #10                 // Method readInts:()Ljava/util/List;
      74: checkcast     #30                 // class java/util/Collection
      77: invokestatic  #36                 // Method kotlin/collections/CollectionsKt.toIntArray:(Ljava/util/Collection;)[I
      80: iconst_0
      81: istore        10
      83: iload_1
      84: iload_2
      85: isub
      86: istore        11
      88: iload         11
      90: newarray       int
      92: astore        12
      94: astore        13
      96: iload         10
      98: iload         11
     100: if_icmpge     119
     103: iload         10
     105: istore        14
     107: aload         12
     109: iload         14
     111: iconst_0
     112: iastore
     113: iinc          10, 1
     116: goto          96
     119: aload         13
     121: aload         12
     123: invokestatic  #42                 // Method kotlin/collections/ArraysKt.plus:([I[I)[I
     126: astore        15
     128: invokestatic  #10                 // Method readInts:()Ljava/util/List;
     131: astore        10
     133: aload         10
     135: iconst_0
     136: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     141: checkcast     #18                 // class java/lang/Number
     144: invokevirtual #22                 // Method java/lang/Number.intValue:()I
     147: istore        11
     149: aload         10
     151: iconst_1
     152: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     157: checkcast     #18                 // class java/lang/Number
     160: invokevirtual #22                 // Method java/lang/Number.intValue:()I
     163: istore        12
     165: aload         10
     167: iconst_2
     168: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     173: checkcast     #18                 // class java/lang/Number
     176: invokevirtual #22                 // Method java/lang/Number.intValue:()I
     179: istore        14
     181: aload         10
     183: iconst_3
     184: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     189: checkcast     #18                 // class java/lang/Number
     192: invokevirtual #22                 // Method java/lang/Number.intValue:()I
     195: istore        16
     197: iload_2
     198: istore        17
     200: iload         17
     202: iload_1
     203: if_icmpge     251
     206: aload         15
     208: iload         17
     210: iload         11
     212: i2l
     213: aload         15
     215: iload         17
     217: iconst_2
     218: isub
     219: iaload
     220: i2l
     221: lmul
     222: iload         12
     224: i2l
     225: aload         15
     227: iload         17
     229: iconst_1
     230: isub
     231: iaload
     232: i2l
     233: lmul
     234: ladd
     235: iload         14
     237: i2l
     238: ladd
     239: iload         16
     241: i2l
     242: lrem
     243: l2i
     244: iastore
     245: iinc          17, 1
     248: goto          200
     251: aload         15
     253: aload         18
     255: swap
     256: invokevirtual #46                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     259: pop
     260: iinc          6, 1
     263: goto          49
     266: aload         5
     268: checkcast     #12                 // class java/util/List
     271: astore_3
     272: aload_3
     273: iconst_0
     274: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     279: checkcast     #48                 // class "[I"
     282: astore        4
     284: aload_3
     285: iconst_1
     286: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     291: checkcast     #48                 // class "[I"
     294: astore        5
     296: aload_3
     297: iconst_2
     298: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     303: checkcast     #48                 // class "[I"
     306: astore        6
     308: lconst_0
     309: lstore        7
     311: lconst_0
     312: lstore        9
     314: lconst_0
     315: lstore        11
     317: lconst_0
     318: lstore        13
     320: iconst_0
     321: istore        15
     323: aload         4
     325: arraylength
     326: istore        16
     328: iload         15
     330: iload         16
     332: if_icmpge     461
     335: aload         4
     337: iload         15
     339: iaload
     340: aload         5
     342: iload         15
     344: iaload
     345: if_icmpge     365
     348: lload         7
     350: aload         5
     352: iload         15
     354: iaload
     355: aload         4
     357: iload         15
     359: iaload
     360: isub
     361: i2l
     362: ladd
     363: lstore        7
     365: lload         11
     367: iconst_0
     368: aload         5
     370: iload         15
     372: iaload
     373: aload         6
     375: iload         15
     377: iaload
     378: iadd
     379: aload         4
     381: iload         15
     383: iaload
     384: isub
     385: invokestatic  #54                 // Method java/lang/Math.max:(II)I
     388: i2l
     389: ladd
     390: lstore        11
     392: aload         4
     394: iload         15
     396: iaload
     397: aload         5
     399: iload         15
     401: iaload
     402: aload         6
     404: iload         15
     406: iaload
     407: iadd
     408: if_icmple     434
     411: lload         9
     413: aload         4
     415: iload         15
     417: iaload
     418: aload         5
     420: iload         15
     422: iaload
     423: isub
     424: aload         6
     426: iload         15
     428: iaload
     429: isub
     430: i2l
     431: ladd
     432: lstore        9
     434: lload         13
     436: iconst_0
     437: aload         4
     439: iload         15
     441: iaload
     442: aload         5
     444: iload         15
     446: iaload
     447: isub
     448: invokestatic  #54                 // Method java/lang/Math.max:(II)I
     451: i2l
     452: ladd
     453: lstore        13
     455: iinc          15, 1
     458: goto          328
     461: lload         7
     463: lload         13
     465: lcmp
     466: ifgt          477
     469: lload         9
     471: lload         11
     473: lcmp
     474: ifle          481
     477: ldc2_w        #55                 // long -1l
     480: lreturn
     481: lload         7
     483: lload         9
     485: invokestatic  #59                 // Method java/lang/Math.max:(JJ)J
     488: lreturn

  public static final void main();
    Code:
       0: invokestatic  #83                 // 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           #85                 // class java/lang/StringBuilder
      18: dup
      19: invokespecial #87                 // Method java/lang/StringBuilder."<init>":()V
      22: ldc           #89                 // String Case #
      24: invokevirtual #93                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      27: iload_2
      28: iconst_1
      29: iadd
      30: invokevirtual #96                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      33: ldc           #98                 // String :
      35: invokevirtual #93                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      38: invokestatic  #100                // Method solve:()J
      41: invokevirtual #103                // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
      44: invokevirtual #107                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      47: getstatic     #113                // Field java/lang/System.out:Ljava/io/PrintStream;
      50: swap
      51: invokevirtual #119                // 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  #126                // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
       3: dup
       4: invokestatic  #131                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
       7: areturn

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

  private static final java.util.List<java.lang.String> readStrings();
    Code:
       0: invokestatic  #133                // Method readLn:()Ljava/lang/String;
       3: checkcast     #143                // class java/lang/CharSequence
       6: iconst_1
       7: anewarray     #145                // class java/lang/String
      10: astore_0
      11: aload_0
      12: iconst_0
      13: ldc           #147                // String
      15: aastore
      16: aload_0
      17: iconst_0
      18: iconst_0
      19: bipush        6
      21: aconst_null
      22: invokestatic  #153                // 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  #156                // Method readStrings:()Ljava/util/List;
       3: checkcast     #158                // 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  #162                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      21: invokespecial #28                 // Method java/util/ArrayList."<init>":(I)V
      24: checkcast     #30                 // class java/util/Collection
      27: astore_3
      28: iconst_0
      29: istore        4
      31: aload_2
      32: invokeinterface #166,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      37: astore        5
      39: aload         5
      41: invokeinterface #172,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      46: ifeq          92
      49: aload         5
      51: invokeinterface #176,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      56: astore        6
      58: aload_3
      59: aload         6
      61: checkcast     #145                // class java/lang/String
      64: astore        7
      66: astore        9
      68: iconst_0
      69: istore        8
      71: aload         7
      73: invokestatic  #139                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      76: nop
      77: invokestatic  #180                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      80: aload         9
      82: swap
      83: invokeinterface #181,  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  #195                // Method main:()V
       3: return
}


package facebook.y2020.round1

private fun solve(): Int {
	val (n, m, k, _) = readInts()
	val (p, q) = listOf(n, m).map { size -> readInts().toMutableList().also { list ->
		val (a, b, c, d) = readInts()
		for (i in k until size) {
			list.add(((a.toLong() * list[i - 2] + b.toLong() * list[i - 1] + c) % d + 1).toInt())
		}
	}.sorted() }
	var (low, high) = 0 to (p[0] - q[0]).abs() + q.last() - q[0]
	while (low + 1 < high) {
		val time = (low + high) / 2
		var i = 0
		for (x in p) {
			val extraTime = (time - (x - q[i]).abs()).takeIf { it >= 0 } ?: continue
			val y = maxOf(q[i] + extraTime, x + extraTime / 2)
			while (i < m && q[i] <= y) i++
			if (i == m) break
		}
		if (i == m) high = time else low = time
	}
	return high
}

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

private fun Int.abs() = kotlin.math.abs(this)
private fun readLn() = readLine()!!
private fun readInt() = readLn().toInt()
private fun readStrings() = readLn().split(" ")
private fun readInts() = readStrings().map { it.toInt() }

Compiled from "b.kt"
public final class facebook.y2020.round1.BKt {
  private static final int 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 #21                 // 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 #21                 // Method java/lang/Number.intValue:()I
      31: istore_2
      32: aload_0
      33: iconst_2
      34: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      39: checkcast     #18                 // class java/lang/Number
      42: invokevirtual #21                 // Method java/lang/Number.intValue:()I
      45: istore_3
      46: iconst_2
      47: anewarray     #23                 // class java/lang/Integer
      50: astore        5
      52: aload         5
      54: iconst_0
      55: iload_1
      56: invokestatic  #27                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      59: aastore
      60: aload         5
      62: iconst_1
      63: iload_2
      64: invokestatic  #27                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      67: aastore
      68: aload         5
      70: invokestatic  #33                 // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
      73: checkcast     #35                 // class java/lang/Iterable
      76: astore        5
      78: iconst_0
      79: istore        6
      81: aload         5
      83: astore        7
      85: new           #37                 // class java/util/ArrayList
      88: dup
      89: aload         5
      91: bipush        10
      93: invokestatic  #41                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      96: invokespecial #45                 // Method java/util/ArrayList."<init>":(I)V
      99: checkcast     #47                 // class java/util/Collection
     102: astore        8
     104: iconst_0
     105: istore        9
     107: aload         7
     109: invokeinterface #51,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     114: astore        10
     116: aload         10
     118: invokeinterface #57,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     123: ifeq          341
     126: aload         10
     128: invokeinterface #61,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     133: astore        11
     135: aload         8
     137: aload         11
     139: checkcast     #18                 // class java/lang/Number
     142: invokevirtual #21                 // Method java/lang/Number.intValue:()I
     145: istore        12
     147: astore        23
     149: iconst_0
     150: istore        13
     152: invokestatic  #10                 // Method readInts:()Ljava/util/List;
     155: checkcast     #47                 // class java/util/Collection
     158: invokestatic  #65                 // Method kotlin/collections/CollectionsKt.toMutableList:(Ljava/util/Collection;)Ljava/util/List;
     161: astore        14
     163: aload         14
     165: astore        15
     167: iconst_0
     168: istore        16
     170: invokestatic  #10                 // Method readInts:()Ljava/util/List;
     173: astore        17
     175: aload         17
     177: iconst_0
     178: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     183: checkcast     #18                 // class java/lang/Number
     186: invokevirtual #21                 // Method java/lang/Number.intValue:()I
     189: istore        18
     191: aload         17
     193: iconst_1
     194: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     199: checkcast     #18                 // class java/lang/Number
     202: invokevirtual #21                 // Method java/lang/Number.intValue:()I
     205: istore        19
     207: aload         17
     209: iconst_2
     210: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     215: checkcast     #18                 // class java/lang/Number
     218: invokevirtual #21                 // Method java/lang/Number.intValue:()I
     221: istore        20
     223: aload         17
     225: iconst_3
     226: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     231: checkcast     #18                 // class java/lang/Number
     234: invokevirtual #21                 // Method java/lang/Number.intValue:()I
     237: istore        21
     239: iload_3
     240: istore        22
     242: iload         22
     244: iload         12
     246: if_icmpge     320
     249: aload         15
     251: iload         18
     253: i2l
     254: aload         15
     256: iload         22
     258: iconst_2
     259: isub
     260: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     265: checkcast     #18                 // class java/lang/Number
     268: invokevirtual #69                 // Method java/lang/Number.longValue:()J
     271: lmul
     272: iload         19
     274: i2l
     275: aload         15
     277: iload         22
     279: iconst_1
     280: isub
     281: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     286: checkcast     #18                 // class java/lang/Number
     289: invokevirtual #69                 // Method java/lang/Number.longValue:()J
     292: lmul
     293: ladd
     294: iload         20
     296: i2l
     297: ladd
     298: iload         21
     300: i2l
     301: lrem
     302: lconst_1
     303: ladd
     304: l2i
     305: invokestatic  #27                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     308: invokeinterface #73,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     313: pop
     314: iinc          22, 1
     317: goto          242
     320: nop
     321: aload         14
     323: checkcast     #35                 // class java/lang/Iterable
     326: invokestatic  #77                 // Method kotlin/collections/CollectionsKt.sorted:(Ljava/lang/Iterable;)Ljava/util/List;
     329: aload         23
     331: swap
     332: invokeinterface #78,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     337: pop
     338: goto          116
     341: aload         8
     343: checkcast     #12                 // class java/util/List
     346: nop
     347: astore        4
     349: aload         4
     351: iconst_0
     352: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     357: checkcast     #12                 // class java/util/List
     360: astore        5
     362: aload         4
     364: iconst_1
     365: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     370: checkcast     #12                 // class java/util/List
     373: astore        6
     375: iconst_0
     376: invokestatic  #27                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     379: aload         5
     381: iconst_0
     382: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     387: checkcast     #18                 // class java/lang/Number
     390: invokevirtual #21                 // Method java/lang/Number.intValue:()I
     393: aload         6
     395: iconst_0
     396: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     401: checkcast     #18                 // class java/lang/Number
     404: invokevirtual #21                 // Method java/lang/Number.intValue:()I
     407: isub
     408: invokestatic  #82                 // Method abs:(I)I
     411: aload         6
     413: invokestatic  #86                 // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     416: checkcast     #18                 // class java/lang/Number
     419: invokevirtual #21                 // Method java/lang/Number.intValue:()I
     422: iadd
     423: aload         6
     425: iconst_0
     426: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     431: checkcast     #18                 // class java/lang/Number
     434: invokevirtual #21                 // Method java/lang/Number.intValue:()I
     437: isub
     438: invokestatic  #27                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     441: invokestatic  #92                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     444: astore        7
     446: aload         7
     448: invokevirtual #97                 // Method kotlin/Pair.component1:()Ljava/lang/Object;
     451: checkcast     #18                 // class java/lang/Number
     454: invokevirtual #21                 // Method java/lang/Number.intValue:()I
     457: istore        8
     459: aload         7
     461: invokevirtual #100                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     464: checkcast     #18                 // class java/lang/Number
     467: invokevirtual #21                 // Method java/lang/Number.intValue:()I
     470: istore        9
     472: iload         8
     474: iconst_1
     475: iadd
     476: iload         9
     478: if_icmpge     695
     481: iload         8
     483: iload         9
     485: iadd
     486: iconst_2
     487: idiv
     488: istore        10
     490: iconst_0
     491: istore        11
     493: aload         5
     495: invokeinterface #101,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     500: astore        12
     502: aload         12
     504: invokeinterface #57,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     509: ifeq          675
     512: aload         12
     514: invokeinterface #61,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     519: checkcast     #18                 // class java/lang/Number
     522: invokevirtual #21                 // Method java/lang/Number.intValue:()I
     525: istore        13
     527: iload         10
     529: iload         13
     531: aload         6
     533: iload         11
     535: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     540: checkcast     #18                 // class java/lang/Number
     543: invokevirtual #21                 // Method java/lang/Number.intValue:()I
     546: isub
     547: invokestatic  #82                 // Method abs:(I)I
     550: isub
     551: invokestatic  #27                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     554: astore        16
     556: aload         16
     558: checkcast     #18                 // class java/lang/Number
     561: invokevirtual #21                 // Method java/lang/Number.intValue:()I
     564: istore        17
     566: iconst_0
     567: istore        18
     569: iload         17
     571: iflt          578
     574: iconst_1
     575: goto          579
     578: iconst_0
     579: ifeq          587
     582: aload         16
     584: goto          588
     587: aconst_null
     588: dup
     589: ifnull        598
     592: invokevirtual #102                // Method java/lang/Integer.intValue:()I
     595: goto          602
     598: pop
     599: goto          502
     602: istore        14
     604: aload         6
     606: iload         11
     608: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     613: checkcast     #18                 // class java/lang/Number
     616: invokevirtual #21                 // Method java/lang/Number.intValue:()I
     619: iload         14
     621: iadd
     622: iload         13
     624: iload         14
     626: iconst_2
     627: idiv
     628: iadd
     629: invokestatic  #108                // Method java/lang/Math.max:(II)I
     632: istore        15
     634: iload         11
     636: iload_2
     637: if_icmpge     666
     640: aload         6
     642: iload         11
     644: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     649: checkcast     #18                 // class java/lang/Number
     652: invokevirtual #21                 // Method java/lang/Number.intValue:()I
     655: iload         15
     657: if_icmpgt     666
     660: iinc          11, 1
     663: goto          634
     666: iload         11
     668: iload_2
     669: if_icmpne     502
     672: goto          675
     675: iload         11
     677: iload_2
     678: if_icmpne     688
     681: iload         10
     683: istore        9
     685: goto          472
     688: iload         10
     690: istore        8
     692: goto          472
     695: iload         9
     697: ireturn

  public static final void main();
    Code:
       0: invokestatic  #146                // 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           #148                // 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: invokestatic  #163                // Method solve:()I
      41: invokevirtual #159                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      44: invokevirtual #167                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      47: getstatic     #173                // Field java/lang/System.out:Ljava/io/PrintStream;
      50: swap
      51: invokevirtual #179                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      54: nop
      55: iinc          1, 1
      58: goto          6
      61: return

  private static final int abs(int);
    Code:
       0: iload_0
       1: invokestatic  #181                // Method java/lang/Math.abs:(I)I
       4: ireturn

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

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

  private static final java.util.List<java.lang.String> readStrings();
    Code:
       0: invokestatic  #195                // Method readLn:()Ljava/lang/String;
       3: checkcast     #203                // class java/lang/CharSequence
       6: iconst_1
       7: anewarray     #205                // class java/lang/String
      10: astore_0
      11: aload_0
      12: iconst_0
      13: ldc           #207                // String
      15: aastore
      16: aload_0
      17: iconst_0
      18: iconst_0
      19: bipush        6
      21: aconst_null
      22: invokestatic  #213                // 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  #216                // Method readStrings:()Ljava/util/List;
       3: checkcast     #35                 // class java/lang/Iterable
       6: astore_0
       7: iconst_0
       8: istore_1
       9: aload_0
      10: astore_2
      11: new           #37                 // class java/util/ArrayList
      14: dup
      15: aload_0
      16: bipush        10
      18: invokestatic  #41                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      21: invokespecial #45                 // Method java/util/ArrayList."<init>":(I)V
      24: checkcast     #47                 // class java/util/Collection
      27: astore_3
      28: iconst_0
      29: istore        4
      31: aload_2
      32: invokeinterface #51,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      37: astore        5
      39: aload         5
      41: invokeinterface #57,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      46: ifeq          92
      49: aload         5
      51: invokeinterface #61,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      56: astore        6
      58: aload_3
      59: aload         6
      61: checkcast     #205                // class java/lang/String
      64: astore        7
      66: astore        9
      68: iconst_0
      69: istore        8
      71: aload         7
      73: invokestatic  #199                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      76: nop
      77: invokestatic  #27                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      80: aload         9
      82: swap
      83: invokeinterface #78,  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  #221                // Method main:()V
       3: return
}