Little Witch Academia
时间限制:C/C++/Rust/Pascal 2秒,其他语言4秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

Again, Akko breaks a wall in little witch academia when she's practicing how to fly on broom! She doesn't want Diana to know about this, as Diana may be mad at her, so she turns to Ursula Sensei for help.

Ursula Sensei gives Akko two kinds of bricks:

  • width , height
  • width , height

Akko can use these two kinds of brick for INFINITE times, and she CANNOT ROTATE the brick.

Now Akko must use these two kinds of bricks to fill the wall with width and height . And in order to make the wall more stable, Akko hopes that between any two adjacent layers, there can be no BRICK GAP up and down except the left and right side.

A legal situation is like this:

And an illegal situation is like this:

as you can see, there's a BRICK GAP in an illegal situation:

Specially, you can fill the wall with only one kind of brick, which means the following situation is legal:

Now Akko wants to know how many different legal situations there are. Two situations are different if and only if in some layer, they have different brick orders.

输入描述:

The Input consists of  lines where the first line gives you the number of test cases , and the following  lines give , showing two different kinds of bricks and the size of the wall, and we can guarantee:

输出描述:

For each test case, you should output the number of legal situations in one line, and your answer should mod .
示例1

输入

复制
3
4 5 3 7
2 4 4 1
2 3 9 5

输出

复制
0
2
14