package gcj.y2023.farewell_d

private fun solve(): Modular {
	val s = readLn()
	val dp = ModularArray(s.length) { 0.toModularUnsafe() }
	var ans = 0.toModularUnsafe()
	for (i in s.indices) {
		if (s[i] !in ".o") continue
		if (s.take(i).all { it in ".>" }) dp[i] = 1.toModularUnsafe()
		for (j in 0 until i) {
			var good = true
			if (s[j] !in ".o") continue
			for (k in j+1 until i) {
				val desired = if (2 * k == i + j) '=' else if (2 * k < i + j) '<' else '>'
				if (s[k] != desired && s[k] != '.') good = false
			}
			if (good) dp[i] += dp[j]
		}
		if (s.drop(i + 1).all { it in ".<" }) ans += dp[i]
	}
	return ans
}

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

//typealias Modular = Double; fun Number.toModular() = toDouble(); fun Number.toModularUnsafe() = toDouble()
//typealias ModularArray = DoubleArray; val ModularArray.data; get() = this

@JvmInline
@Suppress("NOTHING_TO_INLINE")
private value class Modular(val x: Int) {
	companion object {
		const val M = 1000000007; val MOD_BIG_INTEGER = M.toBigInteger()
	}
	inline operator fun plus(that: Modular) = Modular((x + that.x).let { if (it >= M) it - M else it })
	inline operator fun minus(that: Modular) = Modular((x - that.x).let { if (it < 0) it + M else it })
	inline operator fun times(that: Modular) = Modular((x.toLong() * that.x % M).toInt())
	inline operator fun div(that: Modular) = times(that.inverse())
	inline fun inverse() = Modular(x.toBigInteger().modInverse(MOD_BIG_INTEGER).toInt())
	override fun toString() = x.toString()
}
private fun Int.toModularUnsafe() = Modular(this)
private fun Int.toModular() = Modular(if (this >= 0) { if (this < Modular.M) this else this % Modular.M } else { Modular.M - 1 - inv() % Modular.M })
private fun Long.toModular() = Modular((if (this >= 0) { if (this < Modular.M) this else this % Modular.M } else { Modular.M - 1 - inv() % Modular.M }).toInt())
private fun java.math.BigInteger.toModular() = Modular(mod(Modular.MOD_BIG_INTEGER).toInt())
private fun String.toModular() = Modular(fold(0L) { acc, c -> (c - '0' + 10 * acc) % Modular.M }.toInt())

@JvmInline
private value class ModularArray(val data: IntArray) {
	operator fun get(index: Int) = data[index].toModularUnsafe()
	operator fun set(index: Int, value: Modular) { data[index] = value.x }
}
private inline fun ModularArray(n: Int, init: (Int) -> Modular) = ModularArray(IntArray(n) { init(it).x })

private val factorials = mutableListOf(1.toModularUnsafe())
private fun factorial(n: Int): Modular {
	while (n >= factorials.size) factorials.add(factorials.last() * factorials.size.toModularUnsafe())
	return factorials[n]
}
private fun cnk(n: Int, k: Int) = factorial(n) / factorial(k) / factorial(n - k)

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

Compiled from "d_small.kt"
public final class gcj.y2023.farewell_d.D_smallKt {
  private static final java.util.List<gcj.y2023.farewell_d.Modular> factorials;

  private static final int solve();
    Code:
       0: invokestatic  #10                 // Method readLn:()Ljava/lang/String;
       3: astore_0
       4: aload_0
       5: invokevirtual #15                 // Method java/lang/String.length:()I
       8: istore_2
       9: iconst_0
      10: istore_3
      11: iconst_0
      12: istore        4
      14: iload_2
      15: newarray       int
      17: astore        5
      19: iload         4
      21: iload_2
      22: if_icmpge     63
      25: iload         4
      27: istore        6
      29: aload         5
      31: iload         6
      33: iload         6
      35: istore        7
      37: istore        14
      39: astore        13
      41: iconst_0
      42: istore        8
      44: iconst_0
      45: invokestatic  #19                 // Method toModularUnsafe:(I)I
      48: istore        15
      50: aload         13
      52: iload         14
      54: iload         15
      56: iastore
      57: iinc          4, 1
      60: goto          19
      63: aload         5
      65: invokestatic  #25                 // Method gcj/y2023/farewell_d/ModularArray."constructor-impl":([I)[I
      68: astore_1
      69: iconst_0
      70: invokestatic  #19                 // Method toModularUnsafe:(I)I
      73: istore_2
      74: iconst_0
      75: istore_3
      76: aload_0
      77: checkcast     #27                 // class java/lang/CharSequence
      80: invokeinterface #28,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      85: istore        4
      87: iload_3
      88: iload         4
      90: if_icmpge     503
      93: ldc           #30                 // String .o
      95: checkcast     #27                 // class java/lang/CharSequence
      98: aload_0
      99: iload_3
     100: invokevirtual #34                 // Method java/lang/String.charAt:(I)C
     103: iconst_0
     104: iconst_2
     105: aconst_null
     106: invokestatic  #40                 // Method kotlin/text/StringsKt.contains$default:(Ljava/lang/CharSequence;CZILjava/lang/Object;)Z
     109: ifeq          497
     112: aload_0
     113: iload_3
     114: invokestatic  #44                 // Method kotlin/text/StringsKt.take:(Ljava/lang/String;I)Ljava/lang/String;
     117: checkcast     #27                 // class java/lang/CharSequence
     120: astore        5
     122: iconst_0
     123: istore        6
     125: iconst_0
     126: istore        7
     128: iload         7
     130: aload         5
     132: invokeinterface #28,  1           // InterfaceMethod java/lang/CharSequence.length:()I
     137: if_icmpge     184
     140: aload         5
     142: iload         7
     144: invokeinterface #45,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     149: istore        8
     151: iload         8
     153: istore        9
     155: iconst_0
     156: istore        10
     158: ldc           #47                 // String .>
     160: checkcast     #27                 // class java/lang/CharSequence
     163: iload         9
     165: iconst_0
     166: iconst_2
     167: aconst_null
     168: invokestatic  #40                 // Method kotlin/text/StringsKt.contains$default:(Ljava/lang/CharSequence;CZILjava/lang/Object;)Z
     171: ifne          178
     174: iconst_0
     175: goto          185
     178: iinc          7, 1
     181: goto          128
     184: iconst_1
     185: ifeq          197
     188: aload_1
     189: iload_3
     190: iconst_1
     191: invokestatic  #19                 // Method toModularUnsafe:(I)I
     194: invokestatic  #51                 // Method gcj/y2023/farewell_d/ModularArray."set-c6SKC3Y":([III)V
     197: iconst_0
     198: istore        5
     200: iload         5
     202: iload_3
     203: if_icmpge     378
     206: iconst_1
     207: istore        6
     209: ldc           #30                 // String .o
     211: checkcast     #27                 // class java/lang/CharSequence
     214: aload_0
     215: iload         5
     217: invokevirtual #34                 // Method java/lang/String.charAt:(I)C
     220: iconst_0
     221: iconst_2
     222: aconst_null
     223: invokestatic  #40                 // Method kotlin/text/StringsKt.contains$default:(Ljava/lang/CharSequence;CZILjava/lang/Object;)Z
     226: ifeq          372
     229: iload         5
     231: iconst_1
     232: iadd
     233: istore        7
     235: iload         7
     237: iload_3
     238: if_icmpge     308
     241: iconst_2
     242: iload         7
     244: imul
     245: iload_3
     246: iload         5
     248: iadd
     249: if_icmpne     257
     252: bipush        61
     254: goto          275
     257: iconst_2
     258: iload         7
     260: imul
     261: iload_3
     262: iload         5
     264: iadd
     265: if_icmpge     273
     268: bipush        60
     270: goto          275
     273: bipush        62
     275: istore        8
     277: aload_0
     278: iload         7
     280: invokevirtual #34                 // Method java/lang/String.charAt:(I)C
     283: iload         8
     285: if_icmpeq     302
     288: aload_0
     289: iload         7
     291: invokevirtual #34                 // Method java/lang/String.charAt:(I)C
     294: bipush        46
     296: if_icmpeq     302
     299: iconst_0
     300: istore        6
     302: iinc          7, 1
     305: goto          235
     308: iload         6
     310: ifeq          372
     313: iload_3
     314: istore        7
     316: aload_1
     317: iload         7
     319: aload_1
     320: iload         7
     322: invokestatic  #55                 // Method gcj/y2023/farewell_d/ModularArray."get-7DLqRFc":([II)I
     325: istore        8
     327: aload_1
     328: iload         5
     330: invokestatic  #55                 // Method gcj/y2023/farewell_d/ModularArray."get-7DLqRFc":([II)I
     333: istore        9
     335: iconst_0
     336: istore        10
     338: iload         8
     340: iload         9
     342: iadd
     343: istore        11
     345: iconst_0
     346: istore        12
     348: iload         11
     350: ldc           #56                 // int 1000000007
     352: if_icmplt     363
     355: iload         11
     357: ldc           #56                 // int 1000000007
     359: isub
     360: goto          365
     363: iload         11
     365: nop
     366: invokestatic  #60                 // Method gcj/y2023/farewell_d/Modular."constructor-impl":(I)I
     369: invokestatic  #51                 // Method gcj/y2023/farewell_d/ModularArray."set-c6SKC3Y":([III)V
     372: iinc          5, 1
     375: goto          200
     378: aload_0
     379: iload_3
     380: iconst_1
     381: iadd
     382: invokestatic  #63                 // Method kotlin/text/StringsKt.drop:(Ljava/lang/String;I)Ljava/lang/String;
     385: checkcast     #27                 // class java/lang/CharSequence
     388: astore        5
     390: iconst_0
     391: istore        6
     393: iconst_0
     394: istore        7
     396: iload         7
     398: aload         5
     400: invokeinterface #28,  1           // InterfaceMethod java/lang/CharSequence.length:()I
     405: if_icmpge     452
     408: aload         5
     410: iload         7
     412: invokeinterface #45,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     417: istore        8
     419: iload         8
     421: istore        9
     423: iconst_0
     424: istore        10
     426: ldc           #65                 // String .<
     428: checkcast     #27                 // class java/lang/CharSequence
     431: iload         9
     433: iconst_0
     434: iconst_2
     435: aconst_null
     436: invokestatic  #40                 // Method kotlin/text/StringsKt.contains$default:(Ljava/lang/CharSequence;CZILjava/lang/Object;)Z
     439: ifne          446
     442: iconst_0
     443: goto          453
     446: iinc          7, 1
     449: goto          396
     452: iconst_1
     453: ifeq          497
     456: aload_1
     457: iload_3
     458: invokestatic  #55                 // Method gcj/y2023/farewell_d/ModularArray."get-7DLqRFc":([II)I
     461: istore        5
     463: iconst_0
     464: istore        6
     466: iload_2
     467: iload         5
     469: iadd
     470: istore        7
     472: iconst_0
     473: istore        8
     475: iload         7
     477: ldc           #56                 // int 1000000007
     479: if_icmplt     490
     482: iload         7
     484: ldc           #56                 // int 1000000007
     486: isub
     487: goto          492
     490: iload         7
     492: nop
     493: invokestatic  #60                 // Method gcj/y2023/farewell_d/Modular."constructor-impl":(I)I
     496: istore_2
     497: iinc          3, 1
     500: goto          87
     503: iload_2
     504: ireturn

  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     64
      11: iload_1
      12: istore_2
      13: iconst_0
      14: istore_3
      15: new           #101                // class java/lang/StringBuilder
      18: dup
      19: invokespecial #104                // Method java/lang/StringBuilder."<init>":()V
      22: ldc           #106                // String Case #
      24: invokevirtual #110                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      27: iload_2
      28: iconst_1
      29: iadd
      30: invokevirtual #113                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      33: ldc           #115                // String :
      35: invokevirtual #110                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      38: invokestatic  #117                // Method solve:()I
      41: invokestatic  #121                // Method gcj/y2023/farewell_d/Modular."toString-impl":(I)Ljava/lang/String;
      44: invokevirtual #124                // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
      47: invokevirtual #127                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      50: getstatic     #133                // Field java/lang/System.out:Ljava/io/PrintStream;
      53: swap
      54: invokevirtual #139                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      57: nop
      58: iinc          1, 1
      61: goto          6
      64: return

  private static final int toModularUnsafe(int);
    Code:
       0: iload_0
       1: invokestatic  #60                 // Method gcj/y2023/farewell_d/Modular."constructor-impl":(I)I
       4: ireturn

  private static final int toModular(int);
    Code:
       0: iload_0
       1: iflt          21
       4: iload_0
       5: ldc           #56                 // int 1000000007
       7: if_icmpge     14
      10: iload_0
      11: goto          30
      14: iload_0
      15: ldc           #56                 // int 1000000007
      17: irem
      18: goto          30
      21: ldc           #143                // int 1000000006
      23: iload_0
      24: iconst_m1
      25: ixor
      26: ldc           #56                 // int 1000000007
      28: irem
      29: isub
      30: invokestatic  #60                 // Method gcj/y2023/farewell_d/Modular."constructor-impl":(I)I
      33: ireturn

  private static final int toModular(long);
    Code:
       0: lload_0
       1: lconst_0
       2: lcmp
       3: iflt          26
       6: lload_0
       7: ldc2_w        #146                // long 1000000007l
      10: lcmp
      11: ifge          18
      14: lload_0
      15: goto          39
      18: lload_0
      19: ldc           #56                 // int 1000000007
      21: i2l
      22: lrem
      23: goto          39
      26: ldc           #143                // int 1000000006
      28: i2l
      29: lload_0
      30: ldc2_w        #148                // long -1l
      33: lxor
      34: ldc           #56                 // int 1000000007
      36: i2l
      37: lrem
      38: lsub
      39: l2i
      40: invokestatic  #60                 // Method gcj/y2023/farewell_d/Modular."constructor-impl":(I)I
      43: ireturn

  private static final int toModular(java.math.BigInteger);
    Code:
       0: aload_0
       1: getstatic     #155                // Field gcj/y2023/farewell_d/Modular.Companion:Lgcj/y2023/farewell_d/Modular$Companion;
       4: invokevirtual #161                // Method gcj/y2023/farewell_d/Modular$Companion.getMOD_BIG_INTEGER:()Ljava/math/BigInteger;
       7: invokevirtual #167                // Method java/math/BigInteger.mod:(Ljava/math/BigInteger;)Ljava/math/BigInteger;
      10: invokevirtual #170                // Method java/math/BigInteger.intValue:()I
      13: invokestatic  #60                 // Method gcj/y2023/farewell_d/Modular."constructor-impl":(I)I
      16: ireturn

  private static final int toModular(java.lang.String);
    Code:
       0: aload_0
       1: checkcast     #27                 // class java/lang/CharSequence
       4: astore_1
       5: lconst_0
       6: lstore_2
       7: iconst_0
       8: istore        4
      10: lload_2
      11: lstore        5
      13: iconst_0
      14: istore        7
      16: iload         7
      18: aload_1
      19: invokeinterface #28,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      24: if_icmpge     73
      27: aload_1
      28: iload         7
      30: invokeinterface #45,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      35: istore        8
      37: lload         5
      39: iload         8
      41: istore        9
      43: lstore        10
      45: iconst_0
      46: istore        12
      48: iload         9
      50: bipush        48
      52: isub
      53: i2l
      54: bipush        10
      56: i2l
      57: lload         10
      59: lmul
      60: ladd
      61: ldc           #56                 // int 1000000007
      63: i2l
      64: lrem
      65: lstore        5
      67: iinc          7, 1
      70: goto          16
      73: lload         5
      75: l2i
      76: invokestatic  #60                 // Method gcj/y2023/farewell_d/Modular."constructor-impl":(I)I
      79: ireturn

  private static final int[] ModularArray(int, kotlin.jvm.functions.Function1<? super java.lang.Integer, gcj.y2023.farewell_d.Modular>);
    Code:
       0: iconst_0
       1: istore_2
       2: iconst_0
       3: istore_3
       4: iload_0
       5: newarray       int
       7: astore        4
       9: iload_3
      10: iload_0
      11: if_icmpge     45
      14: iload_3
      15: istore        5
      17: aload         4
      19: iload         5
      21: aload_1
      22: iload         5
      24: invokestatic  #188                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      27: invokeinterface #194,  2          // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
      32: checkcast     #58                 // class gcj/y2023/farewell_d/Modular
      35: invokevirtual #197                // Method gcj/y2023/farewell_d/Modular."unbox-impl":()I
      38: iastore
      39: iinc          3, 1
      42: goto          9
      45: aload         4
      47: invokestatic  #25                 // Method gcj/y2023/farewell_d/ModularArray."constructor-impl":([I)[I
      50: areturn

  private static final int factorial(int);
    Code:
       0: iload_0
       1: getstatic     #205                // Field factorials:Ljava/util/List;
       4: invokeinterface #210,  1          // InterfaceMethod java/util/List.size:()I
       9: if_icmplt     67
      12: getstatic     #205                // Field factorials:Ljava/util/List;
      15: getstatic     #205                // Field factorials:Ljava/util/List;
      18: invokestatic  #216                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
      21: checkcast     #58                 // class gcj/y2023/farewell_d/Modular
      24: invokevirtual #197                // Method gcj/y2023/farewell_d/Modular."unbox-impl":()I
      27: istore_1
      28: getstatic     #205                // Field factorials:Ljava/util/List;
      31: invokeinterface #210,  1          // InterfaceMethod java/util/List.size:()I
      36: invokestatic  #19                 // Method toModularUnsafe:(I)I
      39: istore_2
      40: iconst_0
      41: istore_3
      42: iload_1
      43: i2l
      44: iload_2
      45: i2l
      46: lmul
      47: ldc           #56                 // int 1000000007
      49: i2l
      50: lrem
      51: l2i
      52: invokestatic  #60                 // Method gcj/y2023/farewell_d/Modular."constructor-impl":(I)I
      55: invokestatic  #220                // Method gcj/y2023/farewell_d/Modular."box-impl":(I)Lgcj/y2023/farewell_d/Modular;
      58: invokeinterface #224,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      63: pop
      64: goto          0
      67: getstatic     #205                // Field factorials:Ljava/util/List;
      70: iload_0
      71: invokeinterface #228,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      76: checkcast     #58                 // class gcj/y2023/farewell_d/Modular
      79: invokevirtual #197                // Method gcj/y2023/farewell_d/Modular."unbox-impl":()I
      82: ireturn

  private static final int cnk(int, int);
    Code:
       0: iload_0
       1: invokestatic  #233                // Method factorial:(I)I
       4: istore_2
       5: iload_1
       6: invokestatic  #233                // Method factorial:(I)I
       9: istore_3
      10: iconst_0
      11: istore        4
      13: iconst_0
      14: istore        5
      16: iload_3
      17: i2l
      18: invokestatic  #236                // Method java/math/BigInteger.valueOf:(J)Ljava/math/BigInteger;
      21: dup
      22: ldc           #238                // String valueOf(...)
      24: invokestatic  #244                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      27: getstatic     #155                // Field gcj/y2023/farewell_d/Modular.Companion:Lgcj/y2023/farewell_d/Modular$Companion;
      30: invokevirtual #161                // Method gcj/y2023/farewell_d/Modular$Companion.getMOD_BIG_INTEGER:()Ljava/math/BigInteger;
      33: invokevirtual #247                // Method java/math/BigInteger.modInverse:(Ljava/math/BigInteger;)Ljava/math/BigInteger;
      36: invokevirtual #170                // Method java/math/BigInteger.intValue:()I
      39: invokestatic  #60                 // Method gcj/y2023/farewell_d/Modular."constructor-impl":(I)I
      42: istore        5
      44: nop
      45: iconst_0
      46: istore        6
      48: iload_2
      49: i2l
      50: iload         5
      52: i2l
      53: lmul
      54: ldc           #56                 // int 1000000007
      56: i2l
      57: lrem
      58: l2i
      59: invokestatic  #60                 // Method gcj/y2023/farewell_d/Modular."constructor-impl":(I)I
      62: nop
      63: istore_2
      64: iload_0
      65: iload_1
      66: isub
      67: invokestatic  #233                // Method factorial:(I)I
      70: istore_3
      71: iconst_0
      72: istore        4
      74: iconst_0
      75: istore        5
      77: iload_3
      78: i2l
      79: invokestatic  #236                // Method java/math/BigInteger.valueOf:(J)Ljava/math/BigInteger;
      82: dup
      83: ldc           #238                // String valueOf(...)
      85: invokestatic  #244                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      88: getstatic     #155                // Field gcj/y2023/farewell_d/Modular.Companion:Lgcj/y2023/farewell_d/Modular$Companion;
      91: invokevirtual #161                // Method gcj/y2023/farewell_d/Modular$Companion.getMOD_BIG_INTEGER:()Ljava/math/BigInteger;
      94: invokevirtual #247                // Method java/math/BigInteger.modInverse:(Ljava/math/BigInteger;)Ljava/math/BigInteger;
      97: invokevirtual #170                // Method java/math/BigInteger.intValue:()I
     100: invokestatic  #60                 // Method gcj/y2023/farewell_d/Modular."constructor-impl":(I)I
     103: istore        5
     105: nop
     106: iconst_0
     107: istore        6
     109: iload_2
     110: i2l
     111: iload         5
     113: i2l
     114: lmul
     115: ldc           #56                 // int 1000000007
     117: i2l
     118: lrem
     119: l2i
     120: invokestatic  #60                 // Method gcj/y2023/farewell_d/Modular."constructor-impl":(I)I
     123: nop
     124: ireturn

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

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

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

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

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

  public static final int access$toModularUnsafe(int);
    Code:
       0: iload_0
       1: invokestatic  #19                 // Method toModularUnsafe:(I)I
       4: ireturn

  static {};
    Code:
       0: iconst_1
       1: anewarray     #58                 // class gcj/y2023/farewell_d/Modular
       4: astore_0
       5: aload_0
       6: iconst_0
       7: iconst_1
       8: invokestatic  #19                 // Method toModularUnsafe:(I)I
      11: invokestatic  #220                // Method gcj/y2023/farewell_d/Modular."box-impl":(I)Lgcj/y2023/farewell_d/Modular;
      14: aastore
      15: aload_0
      16: invokestatic  #324                // Method kotlin/collections/CollectionsKt.mutableListOf:([Ljava/lang/Object;)Ljava/util/List;
      19: putstatic     #205                // Field factorials:Ljava/util/List;
      22: return
}


package gcj.y2023.farewell_d

private fun solve(): String {
	val (nLeft, nRight, c) = readInts()
	val (leftIn, rightIn) = List(2) { readInts().map { it - 1 } }
	val n = nLeft + nRight
	return List(c) {
		val (cu, cvIn) = readInts().map { it - 1 }
		val cv = nLeft + cvIn
		val nei = List(n) { mutableListOf<Int>() }
		fun addEdge(u: Int, v: Int) { nei[u].add(v); nei[v].add(u) }
		addEdge(cu, cv)
		for (i in leftIn.indices) addEdge(i, leftIn[i])
		for (i in rightIn.indices) addEdge(nLeft + i, nLeft + rightIn[i])
//		val all = LongArray(n)
//		val down = LongArray(n)
		var ans = 0L
		val size = IntArray(n) { 1 }
		fun dfs(v: Int, p: Int) {
			for (u in nei[v]) if (u != p) {
				dfs(u, v)
				size[v] += size[u]
				ans += size[u].toLong() * (n - size[u])
//				down[v] += down[u] + size[u]
			}
		}
		dfs(0, -1)
		ans * 2.0 / (n * (n - 1L))
	}.joinToString(" ")
}

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

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

Compiled from "a_small.kt"
public final class gcj.y2023.farewell_d.A_smallKt {
  private static final java.lang.String 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_2
      47: istore        5
      49: new           #24                 // class java/util/ArrayList
      52: dup
      53: iload         5
      55: invokespecial #28                 // Method java/util/ArrayList."<init>":(I)V
      58: astore        6
      60: iconst_0
      61: istore        7
      63: iload         7
      65: iload         5
      67: if_icmpge     206
      70: iload         7
      72: istore        8
      74: aload         6
      76: iload         8
      78: istore        9
      80: astore        24
      82: iconst_0
      83: istore        10
      85: invokestatic  #10                 // Method readInts:()Ljava/util/List;
      88: checkcast     #30                 // class java/lang/Iterable
      91: astore        11
      93: iconst_0
      94: istore        12
      96: aload         11
      98: astore        13
     100: new           #24                 // class java/util/ArrayList
     103: dup
     104: aload         11
     106: bipush        10
     108: invokestatic  #36                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     111: invokespecial #28                 // Method java/util/ArrayList."<init>":(I)V
     114: checkcast     #38                 // class java/util/Collection
     117: astore        14
     119: iconst_0
     120: istore        15
     122: aload         13
     124: invokeinterface #42,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     129: astore        16
     131: aload         16
     133: invokeinterface #48,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     138: ifeq          186
     141: aload         16
     143: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     148: astore        17
     150: aload         14
     152: aload         17
     154: checkcast     #18                 // class java/lang/Number
     157: invokevirtual #22                 // Method java/lang/Number.intValue:()I
     160: istore        18
     162: astore        19
     164: iconst_0
     165: istore        20
     167: iload         18
     169: iconst_1
     170: isub
     171: invokestatic  #58                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     174: aload         19
     176: swap
     177: invokeinterface #62,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     182: pop
     183: goto          131
     186: aload         14
     188: checkcast     #12                 // class java/util/List
     191: nop
     192: nop
     193: aload         24
     195: swap
     196: invokevirtual #63                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     199: pop
     200: iinc          7, 1
     203: goto          63
     206: aload         6
     208: checkcast     #12                 // class java/util/List
     211: astore        4
     213: aload         4
     215: iconst_0
     216: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     221: checkcast     #12                 // class java/util/List
     224: astore        5
     226: aload         4
     228: iconst_1
     229: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     234: checkcast     #12                 // class java/util/List
     237: astore        6
     239: iload_1
     240: iload_2
     241: iadd
     242: istore        7
     244: new           #24                 // class java/util/ArrayList
     247: dup
     248: iload_3
     249: invokespecial #28                 // Method java/util/ArrayList."<init>":(I)V
     252: astore        8
     254: iconst_0
     255: istore        9
     257: iload         9
     259: iload_3
     260: if_icmpge     700
     263: iload         9
     265: istore        10
     267: aload         8
     269: iload         10
     271: istore        11
     273: astore        24
     275: iconst_0
     276: istore        12
     278: invokestatic  #10                 // Method readInts:()Ljava/util/List;
     281: checkcast     #30                 // class java/lang/Iterable
     284: astore        13
     286: iconst_0
     287: istore        14
     289: aload         13
     291: astore        15
     293: new           #24                 // class java/util/ArrayList
     296: dup
     297: aload         13
     299: bipush        10
     301: invokestatic  #36                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     304: invokespecial #28                 // Method java/util/ArrayList."<init>":(I)V
     307: checkcast     #38                 // class java/util/Collection
     310: astore        16
     312: iconst_0
     313: istore        17
     315: aload         15
     317: invokeinterface #42,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     322: astore        18
     324: aload         18
     326: invokeinterface #48,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     331: ifeq          379
     334: aload         18
     336: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     341: astore        19
     343: aload         16
     345: aload         19
     347: checkcast     #18                 // class java/lang/Number
     350: invokevirtual #22                 // Method java/lang/Number.intValue:()I
     353: istore        20
     355: astore        21
     357: iconst_0
     358: istore        22
     360: iload         20
     362: iconst_1
     363: isub
     364: invokestatic  #58                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     367: aload         21
     369: swap
     370: invokeinterface #62,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     375: pop
     376: goto          324
     379: aload         16
     381: checkcast     #12                 // class java/util/List
     384: nop
     385: astore        23
     387: aload         23
     389: iconst_0
     390: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     395: checkcast     #18                 // class java/lang/Number
     398: invokevirtual #22                 // Method java/lang/Number.intValue:()I
     401: istore        13
     403: aload         23
     405: iconst_1
     406: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     411: checkcast     #18                 // class java/lang/Number
     414: invokevirtual #22                 // Method java/lang/Number.intValue:()I
     417: istore        14
     419: iload_1
     420: iload         14
     422: iadd
     423: istore        15
     425: new           #24                 // class java/util/ArrayList
     428: dup
     429: iload         7
     431: invokespecial #28                 // Method java/util/ArrayList."<init>":(I)V
     434: astore        17
     436: iconst_0
     437: istore        18
     439: iload         18
     441: iload         7
     443: if_icmpge     485
     446: iload         18
     448: istore        19
     450: aload         17
     452: iload         19
     454: istore        20
     456: astore        21
     458: iconst_0
     459: istore        22
     461: new           #24                 // class java/util/ArrayList
     464: dup
     465: invokespecial #66                 // Method java/util/ArrayList."<init>":()V
     468: checkcast     #12                 // class java/util/List
     471: nop
     472: aload         21
     474: swap
     475: invokevirtual #63                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     478: pop
     479: iinc          18, 1
     482: goto          439
     485: aload         17
     487: checkcast     #12                 // class java/util/List
     490: astore        16
     492: aload         16
     494: iload         13
     496: iload         15
     498: invokestatic  #70                 // Method solve$lambda$4$addEdge:(Ljava/util/List;II)V
     501: iconst_0
     502: istore        17
     504: aload         5
     506: checkcast     #38                 // class java/util/Collection
     509: invokeinterface #73,  1           // InterfaceMethod java/util/Collection.size:()I
     514: istore        18
     516: iload         17
     518: iload         18
     520: if_icmpge     551
     523: aload         16
     525: iload         17
     527: aload         5
     529: iload         17
     531: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     536: checkcast     #18                 // class java/lang/Number
     539: invokevirtual #22                 // Method java/lang/Number.intValue:()I
     542: invokestatic  #70                 // Method solve$lambda$4$addEdge:(Ljava/util/List;II)V
     545: iinc          17, 1
     548: goto          516
     551: iconst_0
     552: istore        17
     554: aload         6
     556: checkcast     #38                 // class java/util/Collection
     559: invokeinterface #73,  1           // InterfaceMethod java/util/Collection.size:()I
     564: istore        18
     566: iload         17
     568: iload         18
     570: if_icmpge     605
     573: aload         16
     575: iload_1
     576: iload         17
     578: iadd
     579: iload_1
     580: aload         6
     582: iload         17
     584: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     589: checkcast     #18                 // class java/lang/Number
     592: invokevirtual #22                 // Method java/lang/Number.intValue:()I
     595: iadd
     596: invokestatic  #70                 // Method solve$lambda$4$addEdge:(Ljava/util/List;II)V
     599: iinc          17, 1
     602: goto          566
     605: new           #75                 // class kotlin/jvm/internal/Ref$LongRef
     608: dup
     609: invokespecial #76                 // Method kotlin/jvm/internal/Ref$LongRef."<init>":()V
     612: astore        17
     614: iconst_0
     615: istore        19
     617: iload         7
     619: newarray       int
     621: astore        20
     623: iload         19
     625: iload         7
     627: if_icmpge     646
     630: iload         19
     632: istore        22
     634: aload         20
     636: iload         22
     638: iconst_1
     639: iastore
     640: iinc          19, 1
     643: goto          623
     646: aload         20
     648: astore        18
     650: aload         16
     652: aload         18
     654: aload         17
     656: iload         7
     658: iconst_0
     659: iconst_m1
     660: invokestatic  #80                 // Method solve$lambda$4$dfs:(Ljava/util/List;[ILkotlin/jvm/internal/Ref$LongRef;III)V
     663: aload         17
     665: getfield      #84                 // Field kotlin/jvm/internal/Ref$LongRef.element:J
     668: l2d
     669: ldc2_w        #85                 // double 2.0d
     672: dmul
     673: iload         7
     675: i2l
     676: iload         7
     678: i2l
     679: lconst_1
     680: lsub
     681: lmul
     682: l2d
     683: ddiv
     684: invokestatic  #91                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
     687: aload         24
     689: swap
     690: invokevirtual #63                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     693: pop
     694: iinc          9, 1
     697: goto          257
     700: aload         8
     702: checkcast     #12                 // class java/util/List
     705: checkcast     #30                 // class java/lang/Iterable
     708: ldc           #93                 // String
     710: checkcast     #95                 // class java/lang/CharSequence
     713: aconst_null
     714: aconst_null
     715: iconst_0
     716: aconst_null
     717: aconst_null
     718: bipush        62
     720: aconst_null
     721: invokestatic  #99                 // Method kotlin/collections/CollectionsKt.joinToString$default:(Ljava/lang/Iterable;Ljava/lang/CharSequence;Ljava/lang/CharSequence;Ljava/lang/CharSequence;ILjava/lang/CharSequence;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
     724: areturn

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

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

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

  private static final java.util.List<java.lang.String> readStrings();
    Code:
       0: invokestatic  #180                // Method readLn:()Ljava/lang/String;
       3: checkcast     #95                 // class java/lang/CharSequence
       6: iconst_1
       7: anewarray     #188                // class java/lang/String
      10: astore_0
      11: aload_0
      12: iconst_0
      13: ldc           #93                 // String
      15: aastore
      16: aload_0
      17: iconst_0
      18: iconst_0
      19: bipush        6
      21: aconst_null
      22: invokestatic  #194                // 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  #197                // Method readStrings:()Ljava/util/List;
       3: checkcast     #30                 // class java/lang/Iterable
       6: astore_0
       7: iconst_0
       8: istore_1
       9: aload_0
      10: astore_2
      11: new           #24                 // class java/util/ArrayList
      14: dup
      15: aload_0
      16: bipush        10
      18: invokestatic  #36                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      21: invokespecial #28                 // Method java/util/ArrayList."<init>":(I)V
      24: checkcast     #38                 // class java/util/Collection
      27: astore_3
      28: iconst_0
      29: istore        4
      31: aload_2
      32: invokeinterface #42,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      37: astore        5
      39: aload         5
      41: invokeinterface #48,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      46: ifeq          92
      49: aload         5
      51: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      56: astore        6
      58: aload_3
      59: aload         6
      61: checkcast     #188                // class java/lang/String
      64: astore        7
      66: astore        9
      68: iconst_0
      69: istore        8
      71: aload         7
      73: invokestatic  #184                // 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 #62,  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  #202                // Method main:()V
       3: return

  private static final void solve$lambda$4$addEdge(java.util.List<? extends java.util.List<java.lang.Integer>>, int, int);
    Code:
       0: aload_0
       1: iload_1
       2: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
       7: checkcast     #12                 // class java/util/List
      10: iload_2
      11: invokestatic  #58                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      14: invokeinterface #206,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      19: pop
      20: aload_0
      21: iload_2
      22: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      27: checkcast     #12                 // class java/util/List
      30: iload_1
      31: invokestatic  #58                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      34: invokeinterface #206,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      39: pop
      40: return

  private static final void solve$lambda$4$dfs(java.util.List<? extends java.util.List<java.lang.Integer>>, int[], kotlin.jvm.internal.Ref$LongRef, int, int, int);
    Code:
       0: aload_0
       1: iload         4
       3: invokeinterface #16,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
       8: checkcast     #12                 // class java/util/List
      11: invokeinterface #210,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      16: astore        6
      18: aload         6
      20: invokeinterface #48,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      25: ifeq          99
      28: aload         6
      30: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      35: checkcast     #18                 // class java/lang/Number
      38: invokevirtual #22                 // Method java/lang/Number.intValue:()I
      41: istore        7
      43: iload         7
      45: iload         5
      47: if_icmpeq     18
      50: aload_0
      51: aload_1
      52: aload_2
      53: iload_3
      54: iload         7
      56: iload         4
      58: invokestatic  #80                 // Method solve$lambda$4$dfs:(Ljava/util/List;[ILkotlin/jvm/internal/Ref$LongRef;III)V
      61: aload_1
      62: iload         4
      64: aload_1
      65: iload         4
      67: iaload
      68: aload_1
      69: iload         7
      71: iaload
      72: iadd
      73: iastore
      74: aload_2
      75: aload_2
      76: getfield      #84                 // Field kotlin/jvm/internal/Ref$LongRef.element:J
      79: aload_1
      80: iload         7
      82: iaload
      83: i2l
      84: iload_3
      85: aload_1
      86: iload         7
      88: iaload
      89: isub
      90: i2l
      91: lmul
      92: ladd
      93: putfield      #84                 // Field kotlin/jvm/internal/Ref$LongRef.element:J
      96: goto          18
      99: return
}