package codeforces.kotlinheroes6.practice

fun main() {
	val (_, m) = readInts()
	val a = readLongs()
	val capital = a.withIndex().minByOrNull { it.value }!!.index
	data class Edge(val u: Int, val v: Int, val weight: Long)
	val edges = List(m) {
		val (uIn, vIn, weight) = readLongs()
		Edge((uIn - 1).toInt(), (vIn - 1).toInt(), weight)
	} + List(a.size) {
		Edge(it, capital, a[it] + a[capital])
	}
	val dsu = DisjointSetUnion(a.size)
	var ans = 0L
	for (edge in edges.sortedBy { it.weight }) {
		if (dsu[edge.u] == dsu[edge.v]) continue
		dsu.unite(edge.u, edge.v)
		ans += edge.weight
	}
	println(ans)
}

class DisjointSetUnion(n: Int) {
	val p: IntArray = IntArray(n) { it }
	val r = java.util.Random(566)
	operator fun get(v: Int): Int = if (p[v] == v) v else { p[v] = get(p[v]); p[v] }
	fun unite(v: Int, u: Int) = if (r.nextBoolean()) p[get(v)] = get(u) else p[get(u)] = get(v)
}

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

Compiled from "g.kt"
public final class codeforces.kotlinheroes6.practice.GKt$main$Edge {
  private final int u;

  private final int v;

  private final long weight;

  public codeforces.kotlinheroes6.practice.GKt$main$Edge(int, int, long);
    Code:
       0: aload_0
       1: invokespecial #9                  // Method java/lang/Object."<init>":()V
       4: aload_0
       5: iload_1
       6: putfield      #13                 // Field u:I
       9: aload_0
      10: iload_2
      11: putfield      #16                 // Field v:I
      14: aload_0
      15: lload_3
      16: putfield      #20                 // Field weight:J
      19: return

  public final int getU();
    Code:
       0: aload_0
       1: getfield      #13                 // Field u:I
       4: ireturn

  public final int getV();
    Code:
       0: aload_0
       1: getfield      #16                 // Field v:I
       4: ireturn

  public final long getWeight();
    Code:
       0: aload_0
       1: getfield      #20                 // Field weight:J
       4: lreturn

  public final int component1();
    Code:
       0: aload_0
       1: getfield      #13                 // Field u:I
       4: ireturn

  public final int component2();
    Code:
       0: aload_0
       1: getfield      #16                 // Field v:I
       4: ireturn

  public final long component3();
    Code:
       0: aload_0
       1: getfield      #20                 // Field weight:J
       4: lreturn

  public final codeforces.kotlinheroes6.practice.GKt$main$Edge copy(int, int, long);
    Code:
       0: new           #2                  // class codeforces/kotlinheroes6/practice/GKt$main$Edge
       3: dup
       4: iload_1
       5: iload_2
       6: lload_3
       7: invokespecial #34                 // Method "<init>":(IIJ)V
      10: areturn

  public static codeforces.kotlinheroes6.practice.GKt$main$Edge copy$default(codeforces.kotlinheroes6.practice.GKt$main$Edge, int, int, long, int, java.lang.Object);
    Code:
       0: iload         5
       2: iconst_1
       3: iand
       4: ifeq          12
       7: aload_0
       8: getfield      #13                 // Field u:I
      11: istore_1
      12: iload         5
      14: iconst_2
      15: iand
      16: ifeq          24
      19: aload_0
      20: getfield      #16                 // Field v:I
      23: istore_2
      24: iload         5
      26: iconst_4
      27: iand
      28: ifeq          36
      31: aload_0
      32: getfield      #20                 // Field weight:J
      35: lstore_3
      36: aload_0
      37: iload_1
      38: iload_2
      39: lload_3
      40: invokevirtual #38                 // Method copy:(IIJ)Lcodeforces/kotlinheroes6/practice/GKt$main$Edge;
      43: areturn

  public java.lang.String toString();
    Code:
       0: new           #42                 // class java/lang/StringBuilder
       3: dup
       4: invokespecial #43                 // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #45                 // String Edge(u=
       9: invokevirtual #49                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: aload_0
      13: getfield      #13                 // Field u:I
      16: invokevirtual #52                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      19: ldc           #54                 // String , v=
      21: invokevirtual #49                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      24: aload_0
      25: getfield      #16                 // Field v:I
      28: invokevirtual #52                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      31: ldc           #56                 // String , weight=
      33: invokevirtual #49                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      36: aload_0
      37: getfield      #20                 // Field weight:J
      40: invokevirtual #59                 // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
      43: bipush        41
      45: invokevirtual #62                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      48: invokevirtual #64                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      51: areturn

  public int hashCode();
    Code:
       0: aload_0
       1: getfield      #13                 // Field u:I
       4: invokestatic  #70                 // Method java/lang/Integer.hashCode:(I)I
       7: istore_1
       8: iload_1
       9: bipush        31
      11: imul
      12: aload_0
      13: getfield      #16                 // Field v:I
      16: invokestatic  #70                 // Method java/lang/Integer.hashCode:(I)I
      19: iadd
      20: istore_1
      21: iload_1
      22: bipush        31
      24: imul
      25: aload_0
      26: getfield      #20                 // Field weight:J
      29: invokestatic  #75                 // Method java/lang/Long.hashCode:(J)I
      32: iadd
      33: istore_1
      34: iload_1
      35: ireturn

  public boolean equals(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: if_acmpne     7
       5: iconst_1
       6: ireturn
       7: aload_1
       8: instanceof    #2                  // class codeforces/kotlinheroes6/practice/GKt$main$Edge
      11: ifne          16
      14: iconst_0
      15: ireturn
      16: aload_1
      17: checkcast     #2                  // class codeforces/kotlinheroes6/practice/GKt$main$Edge
      20: astore_2
      21: aload_0
      22: getfield      #13                 // Field u:I
      25: aload_2
      26: getfield      #13                 // Field u:I
      29: if_icmpeq     34
      32: iconst_0
      33: ireturn
      34: aload_0
      35: getfield      #16                 // Field v:I
      38: aload_2
      39: getfield      #16                 // Field v:I
      42: if_icmpeq     47
      45: iconst_0
      46: ireturn
      47: aload_0
      48: getfield      #20                 // Field weight:J
      51: aload_2
      52: getfield      #20                 // Field weight:J
      55: lcmp
      56: ifeq          61
      59: iconst_0
      60: ireturn
      61: iconst_1
      62: ireturn
}

Compiled from "Comparisons.kt"
public final class codeforces.kotlinheroes6.practice.GKt$main$$inlined$sortedBy$1<T> implements java.util.Comparator {
  public codeforces.kotlinheroes6.practice.GKt$main$$inlined$sortedBy$1();
    Code:
       0: aload_0
       1: invokespecial #16                 // Method java/lang/Object."<init>":()V
       4: return

  public final int compare(T, T);
    Code:
       0: aload_1
       1: checkcast     #23                 // class codeforces/kotlinheroes6/practice/GKt$main$Edge
       4: astore_3
       5: iconst_0
       6: istore        4
       8: aload_3
       9: invokevirtual #27                 // Method codeforces/kotlinheroes6/practice/GKt$main$Edge.getWeight:()J
      12: invokestatic  #33                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      15: checkcast     #35                 // class java/lang/Comparable
      18: aload_2
      19: checkcast     #23                 // class codeforces/kotlinheroes6/practice/GKt$main$Edge
      22: astore_3
      23: astore        5
      25: iconst_0
      26: istore        4
      28: aload_3
      29: invokevirtual #27                 // Method codeforces/kotlinheroes6/practice/GKt$main$Edge.getWeight:()J
      32: invokestatic  #33                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      35: aload         5
      37: swap
      38: checkcast     #35                 // class java/lang/Comparable
      41: invokestatic  #41                 // Method kotlin/comparisons/ComparisonsKt.compareValues:(Ljava/lang/Comparable;Ljava/lang/Comparable;)I
      44: ireturn
}

Compiled from "g.kt"
public final class codeforces.kotlinheroes6.practice.GKt {
  public static final void main();
    Code:
       0: invokestatic  #10                 // Method readInts:()Ljava/util/List;
       3: iconst_1
       4: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
       9: checkcast     #18                 // class java/lang/Number
      12: invokevirtual #22                 // Method java/lang/Number.intValue:()I
      15: istore_0
      16: invokestatic  #25                 // Method readLongs:()Ljava/util/List;
      19: astore_1
      20: aload_1
      21: checkcast     #27                 // class java/lang/Iterable
      24: invokestatic  #33                 // Method kotlin/collections/CollectionsKt.withIndex:(Ljava/lang/Iterable;)Ljava/lang/Iterable;
      27: astore_3
      28: iconst_0
      29: istore        4
      31: aload_3
      32: invokeinterface #37,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      37: astore        5
      39: aload         5
      41: invokeinterface #43,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      46: ifne          53
      49: aconst_null
      50: goto          160
      53: aload         5
      55: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      60: astore        6
      62: aload         5
      64: invokeinterface #43,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      69: ifne          77
      72: aload         6
      74: goto          160
      77: aload         6
      79: checkcast     #49                 // class kotlin/collections/IndexedValue
      82: astore        7
      84: iconst_0
      85: istore        9
      87: aload         7
      89: invokevirtual #52                 // Method kotlin/collections/IndexedValue.getValue:()Ljava/lang/Object;
      92: checkcast     #18                 // class java/lang/Number
      95: invokevirtual #56                 // Method java/lang/Number.longValue:()J
      98: lstore        7
     100: aload         5
     102: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     107: astore        9
     109: aload         9
     111: checkcast     #49                 // class kotlin/collections/IndexedValue
     114: astore        10
     116: iconst_0
     117: istore        12
     119: aload         10
     121: invokevirtual #52                 // Method kotlin/collections/IndexedValue.getValue:()Ljava/lang/Object;
     124: checkcast     #18                 // class java/lang/Number
     127: invokevirtual #56                 // Method java/lang/Number.longValue:()J
     130: lstore        10
     132: lload         7
     134: lload         10
     136: lcmp
     137: ifle          148
     140: aload         9
     142: astore        6
     144: lload         10
     146: lstore        7
     148: aload         5
     150: invokeinterface #43,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     155: ifne          100
     158: aload         6
     160: dup
     161: invokestatic  #62                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     164: checkcast     #49                 // class kotlin/collections/IndexedValue
     167: invokevirtual #65                 // Method kotlin/collections/IndexedValue.getIndex:()I
     170: istore_2
     171: new           #67                 // class java/util/ArrayList
     174: dup
     175: iload_0
     176: invokespecial #71                 // Method java/util/ArrayList."<init>":(I)V
     179: astore        4
     181: iconst_0
     182: istore        5
     184: iload         5
     186: iload_0
     187: if_icmpge     290
     190: iload         5
     192: istore        6
     194: aload         4
     196: iload         6
     198: istore        7
     200: astore        18
     202: iconst_0
     203: istore        9
     205: invokestatic  #25                 // Method readLongs:()Ljava/util/List;
     208: astore        10
     210: aload         10
     212: iconst_0
     213: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     218: checkcast     #18                 // class java/lang/Number
     221: invokevirtual #56                 // Method java/lang/Number.longValue:()J
     224: lstore        12
     226: aload         10
     228: iconst_1
     229: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     234: checkcast     #18                 // class java/lang/Number
     237: invokevirtual #56                 // Method java/lang/Number.longValue:()J
     240: lstore        14
     242: aload         10
     244: iconst_2
     245: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     250: checkcast     #18                 // class java/lang/Number
     253: invokevirtual #56                 // Method java/lang/Number.longValue:()J
     256: lstore        16
     258: new           #73                 // class codeforces/kotlinheroes6/practice/GKt$main$Edge
     261: dup
     262: lload         12
     264: lconst_1
     265: lsub
     266: l2i
     267: lload         14
     269: lconst_1
     270: lsub
     271: l2i
     272: lload         16
     274: invokespecial #76                 // Method codeforces/kotlinheroes6/practice/GKt$main$Edge."<init>":(IIJ)V
     277: aload         18
     279: swap
     280: invokevirtual #80                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     283: pop
     284: iinc          5, 1
     287: goto          184
     290: aload         4
     292: checkcast     #12                 // class java/util/List
     295: checkcast     #82                 // class java/util/Collection
     298: aload_1
     299: invokeinterface #85,  1           // InterfaceMethod java/util/List.size:()I
     304: istore        4
     306: astore        18
     308: new           #67                 // class java/util/ArrayList
     311: dup
     312: iload         4
     314: invokespecial #71                 // Method java/util/ArrayList."<init>":(I)V
     317: astore        5
     319: iconst_0
     320: istore        6
     322: iload         6
     324: iload         4
     326: if_icmpge     395
     329: iload         6
     331: istore        7
     333: aload         5
     335: iload         7
     337: istore        9
     339: astore        19
     341: iconst_0
     342: istore        10
     344: new           #73                 // class codeforces/kotlinheroes6/practice/GKt$main$Edge
     347: dup
     348: iload         9
     350: iload_2
     351: aload_1
     352: iload         9
     354: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     359: checkcast     #18                 // class java/lang/Number
     362: invokevirtual #56                 // Method java/lang/Number.longValue:()J
     365: aload_1
     366: iload_2
     367: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     372: checkcast     #18                 // class java/lang/Number
     375: invokevirtual #56                 // Method java/lang/Number.longValue:()J
     378: ladd
     379: invokespecial #76                 // Method codeforces/kotlinheroes6/practice/GKt$main$Edge."<init>":(IIJ)V
     382: aload         19
     384: swap
     385: invokevirtual #80                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     388: pop
     389: iinc          6, 1
     392: goto          322
     395: aload         5
     397: checkcast     #12                 // class java/util/List
     400: aload         18
     402: swap
     403: checkcast     #27                 // class java/lang/Iterable
     406: invokestatic  #89                 // Method kotlin/collections/CollectionsKt.plus:(Ljava/util/Collection;Ljava/lang/Iterable;)Ljava/util/List;
     409: astore_3
     410: new           #91                 // class codeforces/kotlinheroes6/practice/DisjointSetUnion
     413: dup
     414: aload_1
     415: invokeinterface #85,  1           // InterfaceMethod java/util/List.size:()I
     420: invokespecial #92                 // Method codeforces/kotlinheroes6/practice/DisjointSetUnion."<init>":(I)V
     423: astore        4
     425: lconst_0
     426: lstore        5
     428: aload_3
     429: checkcast     #27                 // class java/lang/Iterable
     432: astore        9
     434: iconst_0
     435: istore        10
     437: aload         9
     439: new           #94                 // class codeforces/kotlinheroes6/practice/GKt$main$$inlined$sortedBy$1
     442: dup
     443: invokespecial #96                 // Method codeforces/kotlinheroes6/practice/GKt$main$$inlined$sortedBy$1."<init>":()V
     446: checkcast     #98                 // class java/util/Comparator
     449: invokestatic  #102                // Method kotlin/collections/CollectionsKt.sortedWith:(Ljava/lang/Iterable;Ljava/util/Comparator;)Ljava/util/List;
     452: invokeinterface #103,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     457: astore        7
     459: aload         7
     461: invokeinterface #43,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     466: ifeq          532
     469: aload         7
     471: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     476: checkcast     #73                 // class codeforces/kotlinheroes6/practice/GKt$main$Edge
     479: astore        9
     481: aload         4
     483: aload         9
     485: invokevirtual #106                // Method codeforces/kotlinheroes6/practice/GKt$main$Edge.getU:()I
     488: invokevirtual #109                // Method codeforces/kotlinheroes6/practice/DisjointSetUnion.get:(I)I
     491: aload         4
     493: aload         9
     495: invokevirtual #112                // Method codeforces/kotlinheroes6/practice/GKt$main$Edge.getV:()I
     498: invokevirtual #109                // Method codeforces/kotlinheroes6/practice/DisjointSetUnion.get:(I)I
     501: if_icmpeq     459
     504: aload         4
     506: aload         9
     508: invokevirtual #106                // Method codeforces/kotlinheroes6/practice/GKt$main$Edge.getU:()I
     511: aload         9
     513: invokevirtual #112                // Method codeforces/kotlinheroes6/practice/GKt$main$Edge.getV:()I
     516: invokevirtual #116                // Method codeforces/kotlinheroes6/practice/DisjointSetUnion.unite:(II)V
     519: lload         5
     521: aload         9
     523: invokevirtual #119                // Method codeforces/kotlinheroes6/practice/GKt$main$Edge.getWeight:()J
     526: ladd
     527: lstore        5
     529: goto          459
     532: getstatic     #125                // Field java/lang/System.out:Ljava/io/PrintStream;
     535: lload         5
     537: invokevirtual #131                // Method java/io/PrintStream.println:(J)V
     540: return

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

  private static final java.util.List<java.lang.String> readStrings();
    Code:
       0: invokestatic  #174                // Method readLn:()Ljava/lang/String;
       3: checkcast     #176                // class java/lang/CharSequence
       6: iconst_1
       7: anewarray     #178                // class java/lang/String
      10: astore_0
      11: aload_0
      12: iconst_0
      13: ldc           #180                // String
      15: aastore
      16: aload_0
      17: iconst_0
      18: iconst_0
      19: bipush        6
      21: aconst_null
      22: invokestatic  #186                // 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  #189                // Method readStrings:()Ljava/util/List;
       3: checkcast     #27                 // class java/lang/Iterable
       6: astore_0
       7: iconst_0
       8: istore_1
       9: aload_0
      10: astore_2
      11: new           #67                 // class java/util/ArrayList
      14: dup
      15: aload_0
      16: bipush        10
      18: invokestatic  #193                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      21: invokespecial #71                 // Method java/util/ArrayList."<init>":(I)V
      24: checkcast     #82                 // class java/util/Collection
      27: astore_3
      28: iconst_0
      29: istore        4
      31: aload_2
      32: invokeinterface #37,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      37: astore        5
      39: aload         5
      41: invokeinterface #43,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      46: ifeq          92
      49: aload         5
      51: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      56: astore        6
      58: aload_3
      59: aload         6
      61: checkcast     #178                // 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  #203                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      80: aload         9
      82: swap
      83: invokeinterface #204,  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

  private static final java.util.List<java.lang.Long> readLongs();
    Code:
       0: invokestatic  #189                // Method readStrings:()Ljava/util/List;
       3: checkcast     #27                 // class java/lang/Iterable
       6: astore_0
       7: iconst_0
       8: istore_1
       9: aload_0
      10: astore_2
      11: new           #67                 // class java/util/ArrayList
      14: dup
      15: aload_0
      16: bipush        10
      18: invokestatic  #193                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      21: invokespecial #71                 // Method java/util/ArrayList."<init>":(I)V
      24: checkcast     #82                 // class java/util/Collection
      27: astore_3
      28: iconst_0
      29: istore        4
      31: aload_2
      32: invokeinterface #37,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      37: astore        5
      39: aload         5
      41: invokeinterface #43,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      46: ifeq          92
      49: aload         5
      51: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      56: astore        6
      58: aload_3
      59: aload         6
      61: checkcast     #178                // class java/lang/String
      64: astore        7
      66: astore        9
      68: iconst_0
      69: istore        8
      71: aload         7
      73: invokestatic  #220                // Method java/lang/Long.parseLong:(Ljava/lang/String;)J
      76: nop
      77: invokestatic  #223                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      80: aload         9
      82: swap
      83: invokeinterface #204,  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  #227                // Method main:()V
       3: return
}


package codeforces.vk2022.qual

const val VALUES = "6789TJQKA"
const val SUITS = "CDSH"
val INIT = VALUES.indexOf('9')

fun main() {
	val totalCards = VALUES.length * SUITS.length
	val allCardsList = (0 until totalCards).toList()
	val aliceList = readStrings().map { parseCard(it) }
	val bobList = allCardsList - aliceList.toSet()
	val moveBit = 1L shl totalCards
	val allMask = moveBit - 1
	val aliceMask = aliceList.sumOf { 1L shl it }
	val bobMask = bobList.sumOf { 1L shl it }
	val memo = mutableMapOf<Long, Boolean>()
	val initial = allMask
	fun solve(position: Long): Boolean = memo.getOrPut(position) {
		val move = (position shr totalCards) > 0
		val otherMove = if (move) 0 else moveBit
		val present = position and allMask
		val me = present and (if (move) bobMask else aliceMask)
		var canMove = false
		for (suit in SUITS.indices) {
			for (dir in -1..1 step 2) {
				var canPlayValue = INIT
				while (true) {
					val isPresent = present.hasBit (suit * VALUES.length + canPlayValue)
					if (isPresent) break
					canPlayValue += dir
					if (canPlayValue == VALUES.length) canPlayValue = -1
					if (canPlayValue == -1) break
				}
				if (canPlayValue == -1) continue
				if (canPlayValue == INIT && dir < 0) continue
				val canPlay = suit * VALUES.length + canPlayValue
				val canPlayBit = 1L shl canPlay
				if ((me and canPlayBit) == 0L) continue
				if (me == canPlayBit) return@getOrPut move
				canMove = true
				if (solve(otherMove or present xor canPlayBit) == move) return@getOrPut move
			}
		}
		if (!canMove) solve(otherMove or present) else !move
	}
	println(if (solve(initial)) "Bob" else "Alice")
}

fun parseCard(card: String) = SUITS.indexOf(card[1]) * VALUES.length + VALUES.indexOf(card[0])

private fun Long.bit(index: Int) = shr(index) and 1
private fun Long.hasBit(index: Int) = bit(index) != 0L

private fun readStrings() = readln().split(" ")

Compiled from "d1.kt"
public final class codeforces.vk2022.qual.D1Kt {
  public static final java.lang.String VALUES;

  public static final java.lang.String SUITS;

  private static final int INIT;

  public static final int getINIT();
    Code:
       0: getstatic     #10                 // Field INIT:I
       3: ireturn

  public static final void main();
    Code:
       0: bipush        36
       2: istore_0
       3: iconst_0
       4: iload_0
       5: invokestatic  #18                 // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
       8: checkcast     #20                 // class java/lang/Iterable
      11: invokestatic  #26                 // Method kotlin/collections/CollectionsKt.toList:(Ljava/lang/Iterable;)Ljava/util/List;
      14: astore_1
      15: invokestatic  #30                 // Method readStrings:()Ljava/util/List;
      18: checkcast     #20                 // class java/lang/Iterable
      21: astore_3
      22: iconst_0
      23: istore        4
      25: aload_3
      26: astore        5
      28: new           #32                 // class java/util/ArrayList
      31: dup
      32: aload_3
      33: bipush        10
      35: invokestatic  #36                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      38: invokespecial #40                 // Method java/util/ArrayList."<init>":(I)V
      41: checkcast     #42                 // class java/util/Collection
      44: astore        6
      46: iconst_0
      47: istore        7
      49: aload         5
      51: invokeinterface #46,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      56: astore        8
      58: aload         8
      60: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      65: ifeq          111
      68: aload         8
      70: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      75: astore        9
      77: aload         6
      79: aload         9
      81: checkcast     #58                 // class java/lang/String
      84: astore        10
      86: astore        19
      88: iconst_0
      89: istore        11
      91: aload         10
      93: invokestatic  #62                 // Method parseCard:(Ljava/lang/String;)I
      96: invokestatic  #68                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      99: aload         19
     101: swap
     102: invokeinterface #72,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     107: pop
     108: goto          58
     111: aload         6
     113: checkcast     #74                 // class java/util/List
     116: nop
     117: astore_2
     118: aload_1
     119: checkcast     #20                 // class java/lang/Iterable
     122: aload_2
     123: checkcast     #20                 // class java/lang/Iterable
     126: invokestatic  #78                 // Method kotlin/collections/CollectionsKt.toSet:(Ljava/lang/Iterable;)Ljava/util/Set;
     129: checkcast     #20                 // class java/lang/Iterable
     132: invokestatic  #82                 // Method kotlin/collections/CollectionsKt.minus:(Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/util/List;
     135: astore_3
     136: lconst_1
     137: iload_0
     138: lshl
     139: lstore        4
     141: lload         4
     143: lconst_1
     144: lsub
     145: lstore        6
     147: aload_2
     148: checkcast     #20                 // class java/lang/Iterable
     151: astore        10
     153: lconst_0
     154: lstore        11
     156: aload         10
     158: invokeinterface #46,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     163: astore        13
     165: aload         13
     167: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     172: ifeq          217
     175: aload         13
     177: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     182: astore        14
     184: lload         11
     186: aload         14
     188: checkcast     #84                 // class java/lang/Number
     191: invokevirtual #87                 // Method java/lang/Number.intValue:()I
     194: istore        15
     196: lstore        19
     198: iconst_0
     199: istore        16
     201: lconst_1
     202: iload         15
     204: lshl
     205: lstore        21
     207: lload         19
     209: lload         21
     211: ladd
     212: lstore        11
     214: goto          165
     217: lload         11
     219: lstore        8
     221: aload_3
     222: checkcast     #20                 // class java/lang/Iterable
     225: astore        12
     227: lconst_0
     228: lstore        13
     230: aload         12
     232: invokeinterface #46,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     237: astore        15
     239: aload         15
     241: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     246: ifeq          291
     249: aload         15
     251: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     256: astore        16
     258: lload         13
     260: aload         16
     262: checkcast     #84                 // class java/lang/Number
     265: invokevirtual #87                 // Method java/lang/Number.intValue:()I
     268: istore        17
     270: lstore        19
     272: iconst_0
     273: istore        18
     275: lconst_1
     276: iload         17
     278: lshl
     279: lstore        21
     281: lload         19
     283: lload         21
     285: ladd
     286: lstore        13
     288: goto          239
     291: lload         13
     293: lstore        10
     295: new           #89                 // class java/util/LinkedHashMap
     298: dup
     299: invokespecial #91                 // Method java/util/LinkedHashMap."<init>":()V
     302: checkcast     #93                 // class java/util/Map
     305: astore        12
     307: lload         6
     309: lstore        13
     311: aload         12
     313: iload_0
     314: lload         4
     316: lload         6
     318: lload         10
     320: lload         8
     322: lload         13
     324: invokestatic  #97                 // Method main$solve:(Ljava/util/Map;IJJJJJ)Z
     327: ifeq          335
     330: ldc           #99                 // String Bob
     332: goto          337
     335: ldc           #101                // String Alice
     337: getstatic     #107                // Field java/lang/System.out:Ljava/io/PrintStream;
     340: swap
     341: invokevirtual #113                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     344: return

  public static final int parseCard(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #143                // String card
       3: invokestatic  #149                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: ldc           #151                // String CDSH
       8: checkcast     #153                // class java/lang/CharSequence
      11: aload_0
      12: iconst_1
      13: invokevirtual #157                // Method java/lang/String.charAt:(I)C
      16: iconst_0
      17: iconst_0
      18: bipush        6
      20: aconst_null
      21: invokestatic  #163                // Method kotlin/text/StringsKt.indexOf$default:(Ljava/lang/CharSequence;CIZILjava/lang/Object;)I
      24: bipush        9
      26: imul
      27: ldc           #165                // String 6789TJQKA
      29: checkcast     #153                // class java/lang/CharSequence
      32: aload_0
      33: iconst_0
      34: invokevirtual #157                // Method java/lang/String.charAt:(I)C
      37: iconst_0
      38: iconst_0
      39: bipush        6
      41: aconst_null
      42: invokestatic  #163                // Method kotlin/text/StringsKt.indexOf$default:(Ljava/lang/CharSequence;CIZILjava/lang/Object;)I
      45: iadd
      46: ireturn

  private static final long bit(long, int);
    Code:
       0: lload_0
       1: iload_2
       2: lshr
       3: lconst_1
       4: land
       5: lreturn

  private static final boolean hasBit(long, int);
    Code:
       0: lload_0
       1: iload_2
       2: invokestatic  #173                // Method bit:(JI)J
       5: lconst_0
       6: lcmp
       7: ifeq          14
      10: iconst_1
      11: goto          15
      14: iconst_0
      15: ireturn

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

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

  private static final boolean main$solve(java.util.Map<java.lang.Long, java.lang.Boolean>, int, long, long, long, long, long);
    Code:
       0: aload_0
       1: astore        12
       3: lload         10
       5: invokestatic  #198                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
       8: astore        13
      10: iconst_0
      11: istore        14
      13: aload         12
      15: aload         13
      17: invokeinterface #202,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      22: astore        15
      24: aload         15
      26: ifnonnull     346
      29: iconst_0
      30: istore        16
      32: lload         10
      34: iload_1
      35: lshr
      36: lconst_0
      37: lcmp
      38: ifle          45
      41: iconst_1
      42: goto          46
      45: iconst_0
      46: istore        17
      48: iload         17
      50: ifeq          57
      53: lconst_0
      54: goto          58
      57: lload_2
      58: lstore        18
      60: lload         10
      62: lload         4
      64: land
      65: lstore        20
      67: lload         20
      69: iload         17
      71: ifeq          79
      74: lload         6
      76: goto          81
      79: lload         8
      81: land
      82: lstore        22
      84: iconst_0
      85: istore        24
      87: iconst_0
      88: istore        25
      90: ldc           #151                // String CDSH
      92: checkcast     #153                // class java/lang/CharSequence
      95: invokeinterface #205,  1          // InterfaceMethod java/lang/CharSequence.length:()I
     100: istore        26
     102: iload         25
     104: iload         26
     106: if_icmpge     289
     109: iconst_m1
     110: istore        27
     112: iconst_m1
     113: iconst_1
     114: iconst_2
     115: invokestatic  #211                // Method kotlin/internal/ProgressionUtilKt.getProgressionLastElement:(III)I
     118: istore        28
     120: iload         27
     122: iload         28
     124: if_icmpgt     283
     127: getstatic     #10                 // Field INIT:I
     130: istore        29
     132: nop
     133: lload         20
     135: iload         25
     137: bipush        9
     139: imul
     140: iload         29
     142: iadd
     143: invokestatic  #213                // Method hasBit:(JI)Z
     146: istore        30
     148: iload         30
     150: ifne          179
     153: iload         29
     155: iload         27
     157: iadd
     158: istore        29
     160: iload         29
     162: bipush        9
     164: if_icmpne     170
     167: iconst_m1
     168: istore        29
     170: iload         29
     172: iconst_m1
     173: if_icmpne     132
     176: goto          179
     179: iload         29
     181: iconst_m1
     182: if_icmpeq     270
     185: iload         29
     187: getstatic     #10                 // Field INIT:I
     190: if_icmpne     198
     193: iload         27
     195: iflt          270
     198: iload         25
     200: bipush        9
     202: imul
     203: iload         29
     205: iadd
     206: istore        30
     208: lconst_1
     209: iload         30
     211: lshl
     212: lstore        31
     214: lload         22
     216: lload         31
     218: land
     219: lconst_0
     220: lcmp
     221: ifeq          270
     224: lload         22
     226: lload         31
     228: lcmp
     229: ifne          237
     232: iload         17
     234: goto          324
     237: iconst_1
     238: istore        24
     240: aload_0
     241: iload_1
     242: lload_2
     243: lload         4
     245: lload         6
     247: lload         8
     249: lload         18
     251: lload         20
     253: lor
     254: lload         31
     256: lxor
     257: invokestatic  #97                 // Method main$solve:(Ljava/util/Map;IJJJJJ)Z
     260: iload         17
     262: if_icmpne     270
     265: iload         17
     267: goto          324
     270: iload         27
     272: iload         28
     274: if_icmpeq     283
     277: iinc          27, 2
     280: goto          127
     283: iinc          25, 1
     286: goto          102
     289: iload         24
     291: ifne          314
     294: aload_0
     295: iload_1
     296: lload_2
     297: lload         4
     299: lload         6
     301: lload         8
     303: lload         18
     305: lload         20
     307: lor
     308: invokestatic  #97                 // Method main$solve:(Ljava/util/Map;IJJJJJ)Z
     311: goto          324
     314: iload         17
     316: ifne          323
     319: iconst_1
     320: goto          324
     323: iconst_0
     324: invokestatic  #218                // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
     327: astore        33
     329: aload         12
     331: aload         13
     333: aload         33
     335: invokeinterface #222,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     340: pop
     341: aload         33
     343: goto          348
     346: aload         15
     348: nop
     349: checkcast     #215                // class java/lang/Boolean
     352: invokevirtual #225                // Method java/lang/Boolean.booleanValue:()Z
     355: ireturn

  static {};
    Code:
       0: ldc           #165                // String 6789TJQKA
       2: checkcast     #153                // class java/lang/CharSequence
       5: bipush        57
       7: iconst_0
       8: iconst_0
       9: bipush        6
      11: aconst_null
      12: invokestatic  #163                // Method kotlin/text/StringsKt.indexOf$default:(Ljava/lang/CharSequence;CIZILjava/lang/Object;)I
      15: putstatic     #10                 // Field INIT:I
      18: return
}


package codeforces.vk2022.qual

private fun solve() {
	readln()
	val a = readInts()
	var ans = 1
	var nextHigh = a.last() + 1
	val seen = mutableSetOf<Pair<Int, Int>>()
	for (i in a.indices.reversed()) {
		for (t in 1 downTo 0) {
			val high = a[i] + t
			if (high > nextHigh) continue
			nextHigh = nextHigh.coerceAtMost(high - 1)
			var j = i
			var low = high
			while (true) {
				if (!seen.add(low to j)) break
				while (j > 0 && a[j] > low) j--
				if (j < 0 || a[j] < low - 1 || a[j] > low) break
				low--
				j--
			}
			ans = ans.coerceAtLeast(high - low)
		}
	}
	println(ans)
}

fun main() = repeat(readInt()) { solve() }

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

Compiled from "c.kt"
public final class codeforces.vk2022.qual.CKt {
  private static final void solve();
    Code:
       0: invokestatic  #12                 // Method kotlin/io/ConsoleKt.readln:()Ljava/lang/String;
       3: pop
       4: invokestatic  #16                 // Method readInts:()Ljava/util/List;
       7: astore_0
       8: iconst_1
       9: istore_1
      10: aload_0
      11: invokestatic  #22                 // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
      14: checkcast     #24                 // class java/lang/Number
      17: invokevirtual #28                 // Method java/lang/Number.intValue:()I
      20: iconst_1
      21: iadd
      22: istore_2
      23: new           #30                 // class java/util/LinkedHashSet
      26: dup
      27: invokespecial #33                 // Method java/util/LinkedHashSet."<init>":()V
      30: checkcast     #35                 // class java/util/Set
      33: astore_3
      34: aload_0
      35: checkcast     #37                 // class java/util/Collection
      38: invokeinterface #40,  1           // InterfaceMethod java/util/Collection.size:()I
      43: iconst_m1
      44: iadd
      45: istore        4
      47: iconst_0
      48: iload         4
      50: if_icmpgt     243
      53: iload         4
      55: istore        5
      57: iinc          4, -1
      60: iconst_1
      61: istore        6
      63: iconst_m1
      64: iload         6
      66: if_icmpge     237
      69: aload_0
      70: iload         5
      72: invokeinterface #46,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      77: checkcast     #24                 // class java/lang/Number
      80: invokevirtual #28                 // Method java/lang/Number.intValue:()I
      83: iload         6
      85: iadd
      86: istore        7
      88: iload         7
      90: iload_2
      91: if_icmpgt     231
      94: iload_2
      95: iload         7
      97: iconst_1
      98: isub
      99: invokestatic  #52                 // Method kotlin/ranges/RangesKt.coerceAtMost:(II)I
     102: istore_2
     103: iload         5
     105: istore        8
     107: iload         7
     109: istore        9
     111: nop
     112: aload_3
     113: iload         9
     115: invokestatic  #58                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     118: iload         8
     120: invokestatic  #58                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     123: invokestatic  #64                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     126: invokeinterface #68,  2           // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z
     131: ifeq          221
     134: iload         8
     136: ifle          164
     139: aload_0
     140: iload         8
     142: invokeinterface #46,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     147: checkcast     #24                 // class java/lang/Number
     150: invokevirtual #28                 // Method java/lang/Number.intValue:()I
     153: iload         9
     155: if_icmple     164
     158: iinc          8, -1
     161: goto          134
     164: iload         8
     166: iflt          221
     169: aload_0
     170: iload         8
     172: invokeinterface #46,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     177: checkcast     #24                 // class java/lang/Number
     180: invokevirtual #28                 // Method java/lang/Number.intValue:()I
     183: iload         9
     185: iconst_1
     186: isub
     187: if_icmplt     221
     190: aload_0
     191: iload         8
     193: invokeinterface #46,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     198: checkcast     #24                 // class java/lang/Number
     201: invokevirtual #28                 // Method java/lang/Number.intValue:()I
     204: iload         9
     206: if_icmple     212
     209: goto          221
     212: iinc          9, -1
     215: iinc          8, -1
     218: goto          111
     221: iload_1
     222: iload         7
     224: iload         9
     226: isub
     227: invokestatic  #71                 // Method kotlin/ranges/RangesKt.coerceAtLeast:(II)I
     230: istore_1
     231: iinc          6, -1
     234: goto          63
     237: iconst_0
     238: iload         4
     240: if_icmple     53
     243: getstatic     #77                 // Field java/lang/System.out:Ljava/io/PrintStream;
     246: iload_1
     247: invokevirtual #83                 // Method java/io/PrintStream.println:(I)V
     250: return

  public static final void main();
    Code:
       0: invokestatic  #99                 // Method readInt:()I
       3: istore_0
       4: iconst_0
       5: istore_1
       6: iload_1
       7: iload_0
       8: if_icmpge     24
      11: iload_1
      12: istore_2
      13: iconst_0
      14: istore_3
      15: invokestatic  #101                // Method solve:()V
      18: iinc          1, 1
      21: goto          6
      24: return

  private static final int readInt();
    Code:
       0: invokestatic  #12                 // Method kotlin/io/ConsoleKt.readln:()Ljava/lang/String;
       3: invokestatic  #107                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
       6: ireturn

  private static final java.util.List<java.lang.String> readStrings();
    Code:
       0: invokestatic  #12                 // Method kotlin/io/ConsoleKt.readln:()Ljava/lang/String;
       3: checkcast     #111                // class java/lang/CharSequence
       6: iconst_1
       7: anewarray     #113                // class java/lang/String
      10: astore_0
      11: aload_0
      12: iconst_0
      13: ldc           #115                // String
      15: aastore
      16: aload_0
      17: iconst_0
      18: iconst_0
      19: bipush        6
      21: aconst_null
      22: invokestatic  #121                // 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  #124                // Method readStrings:()Ljava/util/List;
       3: checkcast     #126                // class java/lang/Iterable
       6: astore_0
       7: iconst_0
       8: istore_1
       9: aload_0
      10: astore_2
      11: new           #128                // class java/util/ArrayList
      14: dup
      15: aload_0
      16: bipush        10
      18: invokestatic  #132                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      21: invokespecial #134                // Method java/util/ArrayList."<init>":(I)V
      24: checkcast     #37                 // class java/util/Collection
      27: astore_3
      28: iconst_0
      29: istore        4
      31: aload_2
      32: invokeinterface #138,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      37: astore        5
      39: aload         5
      41: invokeinterface #144,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      46: ifeq          92
      49: aload         5
      51: invokeinterface #148,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      56: astore        6
      58: aload_3
      59: aload         6
      61: checkcast     #113                // class java/lang/String
      64: astore        7
      66: astore        9
      68: iconst_0
      69: istore        8
      71: aload         7
      73: invokestatic  #107                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      76: nop
      77: invokestatic  #58                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      80: aload         9
      82: swap
      83: invokeinterface #149,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      88: pop
      89: goto          39
      92: aload_3
      93: checkcast     #42                 // class java/util/List
      96: nop
      97: areturn

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


package codeforces.vk2022.round1

const val M = 26

private fun solve() {
	readln()
	val s = readln().map { it - 'a' }.toIntArray()
	val count = IntArray(M)
	for (c in s) count[c]++
	val byFreq = count.indices.sortedByDescending { count[it] }
	var answer = s.size + 1
	var answerString = ""
	val a = IntArray(s.size)
	val aCount = IntArray(M)
	for (diff in 1..M) {
		if (s.size % diff != 0) continue
		val need = s.size / diff
		val use = byFreq.take(diff).toSet()
		a.fill(-1)
		aCount.fill(0)
		var current = s.size
		for (i in s.indices) {
			if (s[i] in use && aCount[s[i]] < need) {
				a[i] = s[i]
				aCount[s[i]]++
				current--
			}
		}
		if (current < answer) {
			answer = current
			var j = 0
			for (i in s.indices) {
				if (a[i] != -1) continue
				while (j !in use || aCount[j] == need) j++
				a[i] = j
				aCount[j]++
			}
			answerString = a.joinToString("") { ('a'.code + it).toChar().toString() }
		}
	}
	println(answer)
	println(answerString)
}

fun main() = repeat(readInt()) { solve() }

private fun readInt() = readln().toInt()

Compiled from "c.kt"
public final class codeforces.vk2022.round1.CKt {
  public static final int M;

  private static final void solve();
    Code:
       0: invokestatic  #12                 // Method kotlin/io/ConsoleKt.readln:()Ljava/lang/String;
       3: pop
       4: invokestatic  #12                 // Method kotlin/io/ConsoleKt.readln:()Ljava/lang/String;
       7: checkcast     #14                 // class java/lang/CharSequence
      10: astore_1
      11: iconst_0
      12: istore_2
      13: aload_1
      14: astore_3
      15: new           #16                 // class java/util/ArrayList
      18: dup
      19: aload_1
      20: invokeinterface #20,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      25: invokespecial #24                 // Method java/util/ArrayList."<init>":(I)V
      28: checkcast     #26                 // class java/util/Collection
      31: astore        4
      33: iconst_0
      34: istore        5
      36: iconst_0
      37: istore        6
      39: iload         6
      41: aload_3
      42: invokeinterface #20,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      47: if_icmpge     94
      50: aload_3
      51: iload         6
      53: invokeinterface #30,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      58: istore        7
      60: aload         4
      62: iload         7
      64: istore        8
      66: astore        16
      68: iconst_0
      69: istore        9
      71: iload         8
      73: bipush        97
      75: isub
      76: invokestatic  #36                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      79: aload         16
      81: swap
      82: invokeinterface #40,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      87: pop
      88: iinc          6, 1
      91: goto          39
      94: aload         4
      96: checkcast     #42                 // class java/util/List
      99: nop
     100: checkcast     #26                 // class java/util/Collection
     103: invokestatic  #48                 // Method kotlin/collections/CollectionsKt.toIntArray:(Ljava/util/Collection;)[I
     106: astore_0
     107: bipush        26
     109: newarray       int
     111: astore_1
     112: iconst_0
     113: istore_2
     114: aload_0
     115: arraylength
     116: istore_3
     117: iload_2
     118: iload_3
     119: if_icmpge     147
     122: aload_0
     123: iload_2
     124: iaload
     125: istore        4
     127: aload_1
     128: iload         4
     130: iaload
     131: istore        5
     133: aload_1
     134: iload         4
     136: iload         5
     138: iconst_1
     139: iadd
     140: iastore
     141: iinc          2, 1
     144: goto          117
     147: aload_1
     148: invokestatic  #54                 // Method kotlin/collections/ArraysKt.getIndices:([I)Lkotlin/ranges/IntRange;
     151: checkcast     #56                 // class java/lang/Iterable
     154: astore_3
     155: iconst_0
     156: istore        4
     158: aload_3
     159: new           #58                 // class codeforces/vk2022/round1/CKt$solve$$inlined$sortedByDescending$1
     162: dup
     163: aload_1
     164: invokespecial #61                 // Method codeforces/vk2022/round1/CKt$solve$$inlined$sortedByDescending$1."<init>":([I)V
     167: checkcast     #63                 // class java/util/Comparator
     170: invokestatic  #67                 // Method kotlin/collections/CollectionsKt.sortedWith:(Ljava/lang/Iterable;Ljava/util/Comparator;)Ljava/util/List;
     173: astore_2
     174: aload_0
     175: arraylength
     176: iconst_1
     177: iadd
     178: istore_3
     179: ldc           #69                 // String
     181: astore        4
     183: aload_0
     184: arraylength
     185: newarray       int
     187: astore        5
     189: bipush        26
     191: newarray       int
     193: astore        6
     195: iconst_1
     196: istore        7
     198: iload         7
     200: bipush        27
     202: if_icmpge     475
     205: aload_0
     206: arraylength
     207: iload         7
     209: irem
     210: ifne          469
     213: aload_0
     214: arraylength
     215: iload         7
     217: idiv
     218: istore        8
     220: aload_2
     221: checkcast     #56                 // class java/lang/Iterable
     224: iload         7
     226: invokestatic  #73                 // Method kotlin/collections/CollectionsKt.take:(Ljava/lang/Iterable;I)Ljava/util/List;
     229: checkcast     #56                 // class java/lang/Iterable
     232: invokestatic  #77                 // Method kotlin/collections/CollectionsKt.toSet:(Ljava/lang/Iterable;)Ljava/util/Set;
     235: astore        9
     237: aload         5
     239: iconst_m1
     240: iconst_0
     241: iconst_0
     242: bipush        6
     244: aconst_null
     245: invokestatic  #81                 // Method kotlin/collections/ArraysKt.fill$default:([IIIIILjava/lang/Object;)V
     248: aload         6
     250: iconst_0
     251: iconst_0
     252: iconst_0
     253: bipush        6
     255: aconst_null
     256: invokestatic  #81                 // Method kotlin/collections/ArraysKt.fill$default:([IIIIILjava/lang/Object;)V
     259: aload_0
     260: arraylength
     261: istore        10
     263: iconst_0
     264: istore        11
     266: aload_0
     267: arraylength
     268: istore        12
     270: iload         11
     272: iload         12
     274: if_icmpge     346
     277: aload         9
     279: aload_0
     280: iload         11
     282: iaload
     283: invokestatic  #36                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     286: invokeinterface #86,  2           // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
     291: ifeq          340
     294: aload         6
     296: aload_0
     297: iload         11
     299: iaload
     300: iaload
     301: iload         8
     303: if_icmpge     340
     306: aload         5
     308: iload         11
     310: aload_0
     311: iload         11
     313: iaload
     314: iastore
     315: aload_0
     316: iload         11
     318: iaload
     319: istore        13
     321: aload         6
     323: iload         13
     325: iaload
     326: istore        14
     328: aload         6
     330: iload         13
     332: iload         14
     334: iconst_1
     335: iadd
     336: iastore
     337: iinc          10, -1
     340: iinc          11, 1
     343: goto          270
     346: iload         10
     348: iload_3
     349: if_icmpge     469
     352: iload         10
     354: istore_3
     355: iconst_0
     356: istore        11
     358: iconst_0
     359: istore        12
     361: aload_0
     362: arraylength
     363: istore        13
     365: iload         12
     367: iload         13
     369: if_icmpge     445
     372: aload         5
     374: iload         12
     376: iaload
     377: iconst_m1
     378: if_icmpne     439
     381: aload         9
     383: iload         11
     385: invokestatic  #36                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     388: invokeinterface #86,  2           // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
     393: ifeq          406
     396: aload         6
     398: iload         11
     400: iaload
     401: iload         8
     403: if_icmpne     412
     406: iinc          11, 1
     409: goto          381
     412: aload         5
     414: iload         12
     416: iload         11
     418: iastore
     419: iload         11
     421: istore        14
     423: aload         6
     425: iload         14
     427: iaload
     428: istore        15
     430: aload         6
     432: iload         14
     434: iload         15
     436: iconst_1
     437: iadd
     438: iastore
     439: iinc          12, 1
     442: goto          365
     445: aload         5
     447: ldc           #69                 // String
     449: checkcast     #14                 // class java/lang/CharSequence
     452: aconst_null
     453: aconst_null
     454: iconst_0
     455: aconst_null
     456: invokedynamic #106,  0            // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
     461: bipush        30
     463: aconst_null
     464: invokestatic  #110                // Method kotlin/collections/ArraysKt.joinToString$default:([ILjava/lang/CharSequence;Ljava/lang/CharSequence;Ljava/lang/CharSequence;ILjava/lang/CharSequence;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
     467: astore        4
     469: iinc          7, 1
     472: goto          198
     475: getstatic     #116                // Field java/lang/System.out:Ljava/io/PrintStream;
     478: iload_3
     479: invokevirtual #121                // Method java/io/PrintStream.println:(I)V
     482: getstatic     #116                // Field java/lang/System.out:Ljava/io/PrintStream;
     485: aload         4
     487: invokevirtual #124                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     490: return

  public static final void main();
    Code:
       0: invokestatic  #164                // Method readInt:()I
       3: istore_0
       4: iconst_0
       5: istore_1
       6: iload_1
       7: iload_0
       8: if_icmpge     24
      11: iload_1
      12: istore_2
      13: iconst_0
      14: istore_3
      15: invokestatic  #166                // Method solve:()V
      18: iinc          1, 1
      21: goto          6
      24: return

  private static final int readInt();
    Code:
       0: invokestatic  #12                 // Method kotlin/io/ConsoleKt.readln:()Ljava/lang/String;
       3: invokestatic  #171                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
       6: ireturn

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

  private static final java.lang.CharSequence solve$lambda$2(int);
    Code:
       0: bipush        97
       2: iload_0
       3: iadd
       4: i2c
       5: invokestatic  #179                // Method java/lang/String.valueOf:(C)Ljava/lang/String;
       8: checkcast     #14                 // class java/lang/CharSequence
      11: areturn
}

Compiled from "Comparisons.kt"
public final class codeforces.vk2022.round1.CKt$solve$$inlined$sortedByDescending$1<T> implements java.util.Comparator {
  final int[] $count$inlined;

  public codeforces.vk2022.round1.CKt$solve$$inlined$sortedByDescending$1(int[]);
    Code:
       0: aload_0
       1: aload_1
       2: putfield      #18                 // Field $count$inlined:[I
       5: aload_0
       6: invokespecial #21                 // Method java/lang/Object."<init>":()V
       9: return

  public final int compare(T, T);
    Code:
       0: aload_2
       1: checkcast     #28                 // class java/lang/Number
       4: invokevirtual #32                 // Method java/lang/Number.intValue:()I
       7: istore_3
       8: iconst_0
       9: istore        4
      11: aload_0
      12: getfield      #18                 // Field $count$inlined:[I
      15: iload_3
      16: iaload
      17: invokestatic  #38                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      20: checkcast     #40                 // class java/lang/Comparable
      23: aload_1
      24: checkcast     #28                 // class java/lang/Number
      27: invokevirtual #32                 // Method java/lang/Number.intValue:()I
      30: istore_3
      31: astore        5
      33: iconst_0
      34: istore        4
      36: aload_0
      37: getfield      #18                 // Field $count$inlined:[I
      40: iload_3
      41: iaload
      42: invokestatic  #38                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      45: aload         5
      47: swap
      48: checkcast     #40                 // class java/lang/Comparable
      51: invokestatic  #46                 // Method kotlin/comparisons/ComparisonsKt.compareValues:(Ljava/lang/Comparable;Ljava/lang/Comparable;)I
      54: ireturn
}


package codeforces.vk2022.round1

import kotlin.time.ExperimentalTime
import kotlin.time.measureTime

private fun solve() {
	val (h, w, k) = readInts()
	val zero = 0.toModular()
	val one = 1.toModular()
	val broken = List(k) { readInts().map { it - 1 } }
	val powerOfTwo = Array(h * w + 1) { one }
	for (i in 1 until powerOfTwo.size) {
		powerOfTwo[i] = 2 * powerOfTwo[i - 1]
	}
	var ans = 0.toModular()
	for (hei in 1..h) for (wid in 1..w) {
		for (y0 in 0 until hei) for (y1 in 0 until hei) for (x0 in 0 until wid) for (x1 in 0 until wid) {
			if ((x0 == 0) xor (y0 == 0)) continue
			if ((x1 == wid - 1) xor (y1 == hei - 1)) continue
//			if ((x0 == wid - 1) && (y1 != 0)) continue
//			if ((y0 == hei - 1) && (x1 != 0)) continue
			val emptyByBorders = (if (y0 == 0) 0 else (y0 + x0 - 1)) + (if (y1 == hei - 1) 0 else (hei - y1 + wid - x1 - 3))
			val borderImportant = setOf(0 to x0, y0 to 0, hei - 1 to x1, y1 to wid - 1)
			val variable = hei * wid - emptyByBorders - borderImportant.size
//			println("$hei $wid $y0 $y1 $x0 $x1 -> $variable")
//			ans += powerOfTwo[variable]
		}
	}
	println(ans)
}

@OptIn(ExperimentalTime::class)
fun main() {
	measureTime {
		repeat(readInt()) { solve() }
	}.also { System.err.println(it) }
}

//private fun Int.toModular() = toDouble(); typealias Modular = Double
private fun Int.toModular() = Modular1(this)//toDouble()
private class Modular1 {
	companion object {
		const val M = 998244353
	}
	val x: Int
	@Suppress("ConvertSecondaryConstructorToPrimary")
	constructor(value: Int) { x = (value % M).let { if (it < 0) it + M else it } }
	operator fun plus(that: Modular1) = Modular1((x + that.x) % M)
	operator fun minus(that: Modular1) = Modular1((x + M - that.x) % M)
	operator fun times(that: Modular1) = (x.toLong() * that.x % M).toInt().toModular()
	private fun modInverse() = Modular1(x.toBigInteger().modInverse(M.toBigInteger()).toInt())
	operator fun div(that: Modular1) = times(that.modInverse())
	override fun toString() = x.toString()
}
private operator fun Int.plus(that: Modular1) = Modular1(this) + that
private operator fun Int.minus(that: Modular1) = Modular1(this) - that
private operator fun Int.times(that: Modular1) = Modular1(this) * that
private operator fun Int.div(that: Modular1) = Modular1(this) / that

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

Compiled from "h1_to_upsolve.kt"
public final class codeforces.vk2022.round1.H1_to_upsolveKt {
  private static final void 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: 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 #22                 // Method java/lang/Number.intValue:()I
      45: istore_3
      46: iconst_0
      47: invokestatic  #26                 // Method toModular:(I)Lcodeforces/vk2022/round1/Modular1;
      50: astore        4
      52: iconst_1
      53: invokestatic  #26                 // Method toModular:(I)Lcodeforces/vk2022/round1/Modular1;
      56: astore        5
      58: new           #28                 // class java/util/ArrayList
      61: dup
      62: iload_3
      63: invokespecial #32                 // Method java/util/ArrayList."<init>":(I)V
      66: astore        7
      68: iconst_0
      69: istore        8
      71: iload         8
      73: iload_3
      74: if_icmpge     213
      77: iload         8
      79: istore        9
      81: aload         7
      83: iload         9
      85: istore        10
      87: astore        22
      89: iconst_0
      90: istore        11
      92: invokestatic  #10                 // Method readInts:()Ljava/util/List;
      95: checkcast     #34                 // class java/lang/Iterable
      98: astore        12
     100: iconst_0
     101: istore        13
     103: aload         12
     105: astore        14
     107: new           #28                 // class java/util/ArrayList
     110: dup
     111: aload         12
     113: bipush        10
     115: invokestatic  #40                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     118: invokespecial #32                 // Method java/util/ArrayList."<init>":(I)V
     121: checkcast     #42                 // class java/util/Collection
     124: astore        15
     126: iconst_0
     127: istore        16
     129: aload         14
     131: invokeinterface #46,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     136: astore        17
     138: aload         17
     140: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     145: ifeq          193
     148: aload         17
     150: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     155: astore        18
     157: aload         15
     159: aload         18
     161: checkcast     #18                 // class java/lang/Number
     164: invokevirtual #22                 // Method java/lang/Number.intValue:()I
     167: istore        19
     169: astore        20
     171: iconst_0
     172: istore        21
     174: iload         19
     176: iconst_1
     177: isub
     178: invokestatic  #62                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     181: aload         20
     183: swap
     184: invokeinterface #66,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     189: pop
     190: goto          138
     193: aload         15
     195: checkcast     #12                 // class java/util/List
     198: nop
     199: nop
     200: aload         22
     202: swap
     203: invokevirtual #67                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     206: pop
     207: iinc          8, 1
     210: goto          71
     213: aload         7
     215: checkcast     #12                 // class java/util/List
     218: astore        6
     220: iconst_0
     221: istore        8
     223: iload_1
     224: iload_2
     225: imul
     226: iconst_1
     227: iadd
     228: istore        9
     230: iload         9
     232: anewarray     #69                 // class codeforces/vk2022/round1/Modular1
     235: astore        10
     237: iload         8
     239: iload         9
     241: if_icmpge     261
     244: iload         8
     246: istore        11
     248: aload         10
     250: iload         11
     252: aload         5
     254: aastore
     255: iinc          8, 1
     258: goto          237
     261: aload         10
     263: astore        7
     265: iconst_1
     266: istore        8
     268: aload         7
     270: arraylength
     271: istore        9
     273: iload         8
     275: iload         9
     277: if_icmpge     302
     280: aload         7
     282: iload         8
     284: iconst_2
     285: aload         7
     287: iload         8
     289: iconst_1
     290: isub
     291: aaload
     292: invokestatic  #73                 // Method times:(ILcodeforces/vk2022/round1/Modular1;)Lcodeforces/vk2022/round1/Modular1;
     295: aastore
     296: iinc          8, 1
     299: goto          273
     302: iconst_0
     303: invokestatic  #26                 // Method toModular:(I)Lcodeforces/vk2022/round1/Modular1;
     306: astore        8
     308: iconst_1
     309: istore        9
     311: iload         9
     313: iload_1
     314: if_icmpgt     616
     317: iconst_1
     318: istore        10
     320: iload         10
     322: iload_2
     323: if_icmpgt     604
     326: iconst_0
     327: istore        11
     329: iload         11
     331: iload         9
     333: if_icmpge     592
     336: iconst_0
     337: istore        12
     339: iload         12
     341: iload         9
     343: if_icmpge     586
     346: iconst_0
     347: istore        13
     349: iload         13
     351: iload         10
     353: if_icmpge     580
     356: iconst_0
     357: istore        14
     359: iload         14
     361: iload         10
     363: if_icmpge     574
     366: iload         13
     368: ifne          375
     371: iconst_1
     372: goto          376
     375: iconst_0
     376: iload         11
     378: ifne          385
     381: iconst_1
     382: goto          386
     385: iconst_0
     386: ixor
     387: ifne          568
     390: iload         14
     392: iload         10
     394: iconst_1
     395: isub
     396: if_icmpne     403
     399: iconst_1
     400: goto          404
     403: iconst_0
     404: iload         12
     406: iload         9
     408: iconst_1
     409: isub
     410: if_icmpne     417
     413: iconst_1
     414: goto          418
     417: iconst_0
     418: ixor
     419: ifne          568
     422: iload         11
     424: ifne          431
     427: iconst_0
     428: goto          438
     431: iload         11
     433: iload         13
     435: iadd
     436: iconst_1
     437: isub
     438: iload         12
     440: iload         9
     442: iconst_1
     443: isub
     444: if_icmpne     451
     447: iconst_0
     448: goto          464
     451: iload         9
     453: iload         12
     455: isub
     456: iload         10
     458: iadd
     459: iload         14
     461: isub
     462: iconst_3
     463: isub
     464: iadd
     465: istore        15
     467: iconst_4
     468: anewarray     #75                 // class kotlin/Pair
     471: astore        17
     473: aload         17
     475: iconst_0
     476: iconst_0
     477: invokestatic  #62                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     480: iload         13
     482: invokestatic  #62                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     485: invokestatic  #81                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     488: aastore
     489: aload         17
     491: iconst_1
     492: iload         11
     494: invokestatic  #62                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     497: iconst_0
     498: invokestatic  #62                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     501: invokestatic  #81                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     504: aastore
     505: aload         17
     507: iconst_2
     508: iload         9
     510: iconst_1
     511: isub
     512: invokestatic  #62                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     515: iload         14
     517: invokestatic  #62                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     520: invokestatic  #81                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     523: aastore
     524: aload         17
     526: iconst_3
     527: iload         12
     529: invokestatic  #62                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     532: iload         10
     534: iconst_1
     535: isub
     536: invokestatic  #62                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     539: invokestatic  #81                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     542: aastore
     543: aload         17
     545: invokestatic  #87                 // Method kotlin/collections/SetsKt.setOf:([Ljava/lang/Object;)Ljava/util/Set;
     548: astore        16
     550: iload         9
     552: iload         10
     554: imul
     555: iload         15
     557: isub
     558: aload         16
     560: invokeinterface #92,  1           // InterfaceMethod java/util/Set.size:()I
     565: isub
     566: istore        17
     568: iinc          14, 1
     571: goto          359
     574: iinc          13, 1
     577: goto          349
     580: iinc          12, 1
     583: goto          339
     586: iinc          11, 1
     589: goto          329
     592: iload         10
     594: iload_2
     595: if_icmpeq     604
     598: iinc          10, 1
     601: goto          326
     604: iload         9
     606: iload_1
     607: if_icmpeq     616
     610: iinc          9, 1
     613: goto          317
     616: getstatic     #98                 // Field java/lang/System.out:Ljava/io/PrintStream;
     619: aload         8
     621: invokevirtual #104                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     624: return

  public static final void main();
    Code:
       0: iconst_0
       1: istore_0
       2: getstatic     #146                // Field kotlin/time/TimeSource$Monotonic.INSTANCE:Lkotlin/time/TimeSource$Monotonic;
       5: astore_2
       6: iconst_0
       7: istore_3
       8: aload_2
       9: invokevirtual #150                // Method kotlin/time/TimeSource$Monotonic."markNow-z9LOYto":()J
      12: lstore        4
      14: iconst_0
      15: istore        6
      17: invokestatic  #153                // Method readInt:()I
      20: istore        7
      22: iconst_0
      23: istore        8
      25: iload         8
      27: iload         7
      29: if_icmpge     48
      32: iload         8
      34: istore        9
      36: iconst_0
      37: istore        10
      39: invokestatic  #155                // Method solve:()V
      42: iinc          8, 1
      45: goto          25
      48: nop
      49: nop
      50: lload         4
      52: invokestatic  #161                // Method kotlin/time/TimeSource$Monotonic$ValueTimeMark."elapsedNow-UwyO8pc":(J)J
      55: nop
      56: lstore_0
      57: lload_0
      58: lstore_2
      59: iconst_0
      60: istore        4
      62: getstatic     #164                // Field java/lang/System.err:Ljava/io/PrintStream;
      65: lload_2
      66: invokestatic  #170                // Method kotlin/time/Duration."box-impl":(J)Lkotlin/time/Duration;
      69: invokevirtual #104                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      72: lload_0
      73: pop2
      74: return

  private static final codeforces.vk2022.round1.Modular1 toModular(int);
    Code:
       0: new           #69                 // class codeforces/vk2022/round1/Modular1
       3: dup
       4: iload_0
       5: invokespecial #178                // Method codeforces/vk2022/round1/Modular1."<init>":(I)V
       8: areturn

  private static final codeforces.vk2022.round1.Modular1 plus(int, codeforces.vk2022.round1.Modular1);
    Code:
       0: new           #69                 // class codeforces/vk2022/round1/Modular1
       3: dup
       4: iload_0
       5: invokespecial #178                // Method codeforces/vk2022/round1/Modular1."<init>":(I)V
       8: aload_1
       9: invokevirtual #183                // Method codeforces/vk2022/round1/Modular1.plus:(Lcodeforces/vk2022/round1/Modular1;)Lcodeforces/vk2022/round1/Modular1;
      12: areturn

  private static final codeforces.vk2022.round1.Modular1 minus(int, codeforces.vk2022.round1.Modular1);
    Code:
       0: new           #69                 // class codeforces/vk2022/round1/Modular1
       3: dup
       4: iload_0
       5: invokespecial #178                // Method codeforces/vk2022/round1/Modular1."<init>":(I)V
       8: aload_1
       9: invokevirtual #188                // Method codeforces/vk2022/round1/Modular1.minus:(Lcodeforces/vk2022/round1/Modular1;)Lcodeforces/vk2022/round1/Modular1;
      12: areturn

  private static final codeforces.vk2022.round1.Modular1 times(int, codeforces.vk2022.round1.Modular1);
    Code:
       0: new           #69                 // class codeforces/vk2022/round1/Modular1
       3: dup
       4: iload_0
       5: invokespecial #178                // Method codeforces/vk2022/round1/Modular1."<init>":(I)V
       8: aload_1
       9: invokevirtual #191                // Method codeforces/vk2022/round1/Modular1.times:(Lcodeforces/vk2022/round1/Modular1;)Lcodeforces/vk2022/round1/Modular1;
      12: areturn

  private static final codeforces.vk2022.round1.Modular1 div(int, codeforces.vk2022.round1.Modular1);
    Code:
       0: new           #69                 // class codeforces/vk2022/round1/Modular1
       3: dup
       4: iload_0
       5: invokespecial #178                // Method codeforces/vk2022/round1/Modular1."<init>":(I)V
       8: aload_1
       9: invokevirtual #195                // Method codeforces/vk2022/round1/Modular1.div:(Lcodeforces/vk2022/round1/Modular1;)Lcodeforces/vk2022/round1/Modular1;
      12: areturn

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

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

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

  public static final codeforces.vk2022.round1.Modular1 access$toModular(int);
    Code:
       0: iload_0
       1: invokestatic  #26                 // Method toModular:(I)Lcodeforces/vk2022/round1/Modular1;
       4: areturn
}


package codeforces.vk2022.round1

import kotlin.math.roundToLong
import kotlin.math.sqrt

private fun solve() {
	readln()
	val a = readInts()
	var ans = 1
	val toTest = mutableSetOf<Long>()
	for (i in a.indices) for (j in 0 until i) {
		val ba = a[i] - a[j]
		for (d in 1..ba) {
			if (d * d > ba) break
			if (ba % d != 0) continue
			val e = ba / d
			if (((d xor e) and 1) != 0) continue
			val q = (d + e) / 2
			val x = q.toLong() * q - a[i]
			if (x >= 0) toTest.add(x)
		}
	}
	for (x in toTest) {
		val current = a.count { b ->
			val y = b + x
			val z = sqrt(y.toDouble()).roundToLong()
			y == z * z
		}
		ans = ans.coerceAtLeast(current)
	}
	println(ans)
}

fun main() = repeat(readInt()) { solve() }

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

Compiled from "d.kt"
public final class codeforces.vk2022.round1.DKt {
  private static final void solve();
    Code:
       0: invokestatic  #12                 // Method kotlin/io/ConsoleKt.readln:()Ljava/lang/String;
       3: pop
       4: invokestatic  #16                 // Method readInts:()Ljava/util/List;
       7: astore_0
       8: iconst_1
       9: istore_1
      10: new           #18                 // class java/util/LinkedHashSet
      13: dup
      14: invokespecial #21                 // Method java/util/LinkedHashSet."<init>":()V
      17: checkcast     #23                 // class java/util/Set
      20: astore_2
      21: iconst_0
      22: istore_3
      23: aload_0
      24: checkcast     #25                 // class java/util/Collection
      27: invokeinterface #29,  1           // InterfaceMethod java/util/Collection.size:()I
      32: istore        4
      34: iload_3
      35: iload         4
      37: if_icmpge     200
      40: iconst_0
      41: istore        5
      43: iload         5
      45: iload_3
      46: if_icmpge     194
      49: aload_0
      50: iload_3
      51: invokeinterface #35,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      56: checkcast     #37                 // class java/lang/Number
      59: invokevirtual #40                 // Method java/lang/Number.intValue:()I
      62: aload_0
      63: iload         5
      65: invokeinterface #35,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      70: checkcast     #37                 // class java/lang/Number
      73: invokevirtual #40                 // Method java/lang/Number.intValue:()I
      76: isub
      77: istore        6
      79: iconst_1
      80: istore        7
      82: iload         7
      84: iload         6
      86: if_icmpgt     188
      89: iload         7
      91: iload         7
      93: imul
      94: iload         6
      96: if_icmpgt     188
      99: iload         6
     101: iload         7
     103: irem
     104: ifne          175
     107: iload         6
     109: iload         7
     111: idiv
     112: istore        8
     114: iload         7
     116: iload         8
     118: ixor
     119: iconst_1
     120: iand
     121: ifne          175
     124: iload         7
     126: iload         8
     128: iadd
     129: iconst_2
     130: idiv
     131: istore        9
     133: iload         9
     135: i2l
     136: iload         9
     138: i2l
     139: lmul
     140: aload_0
     141: iload_3
     142: invokeinterface #35,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     147: checkcast     #37                 // class java/lang/Number
     150: invokevirtual #44                 // Method java/lang/Number.longValue:()J
     153: lsub
     154: lstore        10
     156: lload         10
     158: lconst_0
     159: lcmp
     160: iflt          175
     163: aload_2
     164: lload         10
     166: invokestatic  #50                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     169: invokeinterface #54,  2           // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z
     174: pop
     175: iload         7
     177: iload         6
     179: if_icmpeq     188
     182: iinc          7, 1
     185: goto          89
     188: iinc          5, 1
     191: goto          43
     194: iinc          3, 1
     197: goto          34
     200: aload_2
     201: invokeinterface #58,  1           // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     206: astore_3
     207: aload_3
     208: invokeinterface #64,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     213: ifeq          374
     216: aload_3
     217: invokeinterface #68,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     222: checkcast     #37                 // class java/lang/Number
     225: invokevirtual #44                 // Method java/lang/Number.longValue:()J
     228: lstore        4
     230: aload_0
     231: checkcast     #70                 // class java/lang/Iterable
     234: astore        7
     236: iconst_0
     237: istore        8
     239: aload         7
     241: instanceof    #25                 // class java/util/Collection
     244: ifeq          264
     247: aload         7
     249: checkcast     #25                 // class java/util/Collection
     252: invokeinterface #73,  1           // InterfaceMethod java/util/Collection.isEmpty:()Z
     257: ifeq          264
     260: iconst_0
     261: goto          362
     264: iconst_0
     265: istore        9
     267: aload         7
     269: invokeinterface #74,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     274: astore        10
     276: aload         10
     278: invokeinterface #64,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     283: ifeq          360
     286: aload         10
     288: invokeinterface #68,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     293: astore        11
     295: aload         11
     297: checkcast     #37                 // class java/lang/Number
     300: invokevirtual #40                 // Method java/lang/Number.intValue:()I
     303: istore        12
     305: iconst_0
     306: istore        13
     308: iload         12
     310: i2l
     311: lload         4
     313: ladd
     314: lstore        14
     316: lload         14
     318: l2d
     319: invokestatic  #80                 // Method java/lang/Math.sqrt:(D)D
     322: invokestatic  #86                 // Method kotlin/math/MathKt.roundToLong:(D)J
     325: lstore        16
     327: lload         14
     329: lload         16
     331: lload         16
     333: lmul
     334: lcmp
     335: ifne          342
     338: iconst_1
     339: goto          343
     342: iconst_0
     343: ifeq          276
     346: iinc          9, 1
     349: iload         9
     351: ifge          276
     354: invokestatic  #91                 // Method kotlin/collections/CollectionsKt.throwCountOverflow:()V
     357: goto          276
     360: iload         9
     362: istore        6
     364: iload_1
     365: iload         6
     367: invokestatic  #97                 // Method kotlin/ranges/RangesKt.coerceAtLeast:(II)I
     370: istore_1
     371: goto          207
     374: getstatic     #103                // Field java/lang/System.out:Ljava/io/PrintStream;
     377: iload_1
     378: invokevirtual #109                // Method java/io/PrintStream.println:(I)V
     381: return

  public static final void main();
    Code:
       0: invokestatic  #138                // Method readInt:()I
       3: istore_0
       4: iconst_0
       5: istore_1
       6: iload_1
       7: iload_0
       8: if_icmpge     24
      11: iload_1
      12: istore_2
      13: iconst_0
      14: istore_3
      15: invokestatic  #140                // Method solve:()V
      18: iinc          1, 1
      21: goto          6
      24: return

  private static final int readInt();
    Code:
       0: invokestatic  #12                 // Method kotlin/io/ConsoleKt.readln:()Ljava/lang/String;
       3: invokestatic  #148                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
       6: ireturn

  private static final java.util.List<java.lang.String> readStrings();
    Code:
       0: invokestatic  #12                 // Method kotlin/io/ConsoleKt.readln:()Ljava/lang/String;
       3: checkcast     #152                // class java/lang/CharSequence
       6: iconst_1
       7: anewarray     #154                // class java/lang/String
      10: astore_0
      11: aload_0
      12: iconst_0
      13: ldc           #156                // String
      15: aastore
      16: aload_0
      17: iconst_0
      18: iconst_0
      19: bipush        6
      21: aconst_null
      22: invokestatic  #162                // 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  #165                // Method readStrings:()Ljava/util/List;
       3: checkcast     #70                 // class java/lang/Iterable
       6: astore_0
       7: iconst_0
       8: istore_1
       9: aload_0
      10: astore_2
      11: new           #167                // class java/util/ArrayList
      14: dup
      15: aload_0
      16: bipush        10
      18: invokestatic  #171                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      21: invokespecial #173                // Method java/util/ArrayList."<init>":(I)V
      24: checkcast     #25                 // class java/util/Collection
      27: astore_3
      28: iconst_0
      29: istore        4
      31: aload_2
      32: invokeinterface #74,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      37: astore        5
      39: aload         5
      41: invokeinterface #64,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      46: ifeq          92
      49: aload         5
      51: invokeinterface #68,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      56: astore        6
      58: aload_3
      59: aload         6
      61: checkcast     #154                // class java/lang/String
      64: astore        7
      66: astore        9
      68: iconst_0
      69: istore        8
      71: aload         7
      73: invokestatic  #148                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      76: nop
      77: invokestatic  #176                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      80: aload         9
      82: swap
      83: invokeinterface #177,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      88: pop
      89: goto          39
      92: aload_3
      93: checkcast     #31                 // class java/util/List
      96: nop
      97: areturn

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