8628: Cyber Painter

内存限制:128 MB 时间限制:6 S
题面:传统 评测方式:文本比较 上传者:
提交:2 通过:0

题目描述

In the world of Cyberpunk, all paintings are done by using lasers. As a cyber painter, painting with lasers is your daily job.

You have a laser painting board with n rows and mm columns of laser emitters. The distance between rows is 1, and so is the distance between columns. Each laser emitter can emit a laser with a length of 0.5 in four directions. Specifically, you can set an integer between and 15 as the state value for each laser emitter, which can be denoted by a four-bit binary number (X1X2X3X4)2 (For example, 11=(1011)2). The meaning of the state value is as follows:

  • X1=1: The laser emitter emits a laser of length 0.50.5 in the upward direction.
  • X2=1: The laser emitter emits a laser of length 0.50.5 in the right direction.
  • X3=1: The laser emitter emits a laser of length 0.50.5 in the downward direction.
  • X4=1: The laser emitter emits a laser of length 0.50.5 in the left direction.
Given n×m integers between 0 and 15, you need to assign an integer to each laser emitter as its state value. You are curious about the expectation of the number of squares that can be formed by the laser if the n×m integers are assigned uniformly at random, where the squares can be of arbitrary edge length.

输入格式

The first line contains an integer T 1T104), indicating the number of test cases.

The first line of each test case contains two integers n and m (1n×m105), indicating the number of rows and columns of the laser emitters.

The second line of each test case contains 16 integers a0,a1,,a15 (0ain×mi=015ai=n×m), where a_iai indicates the number of integer ii.

It guaranteed that the sum of n×m over all test cases won't exceed 106.

输出格式

For each test case, output the expectation of the number of squares that can be formed by the laser in a single line. You should output the answer modulo 109+7. Formally, let M=109+7. It can be shown that the answer can be expressed as an irreducible fraction qp, where p and q are integers and q!0(modM). Output the integer equal to p×q1modM. In other words, output such an integer xx that 0x<M andxqp(modM).

输入样例 复制

3
2 2
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4
2 2
0 0 0 1 0 0 1 0 0 1 0 0 1 0 0 0
3 3
0 0 0 0 0 0 1 0 0 1 0 1 1 1 2 2

输出样例 复制

1
41666667
41699736