logo AlgoBeat OnlineJudge
登录 注册

#209476. [ICPC 2018 Qingdao R] Flippy Sequence

内存限制:256 MiB 时间限制:1000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

DreamGrid has just found two binary sequences and ( for all ) from his virtual machine! He would like to perform the operation described below exactly twice, so that holds for all after the two operations.

The operation is: Select two integers and (), change to for all .

DreamGrid would like to know the number of ways to do so.

We use the following rules to determine whether two ways are different:

  • Let , where , be a valid operation pair denoting that DreamGrid selects integers and for the first operation and integers and for the second operation;
  • Let , where , be another valid operation pair denoting that DreamGrid selects integers and for the first operation and integers and for the second operation.
  • and are considered different, if there exists an integer () such that .

输入格式

There are multiple test cases. The first line of the input contains an integer , indicating the number of test cases. For each test case:

The first line contains an integer (), indicating the length of two binary sequences.

The second line contains a string () of length , indicating the first binary sequence.

The third line contains a string () of length , indicating the second binary sequence.

It's guaranteed that the sum of in all test cases will not exceed .

输出格式

For each test case, output an integer denoting the answer.

样例

样例输入 1

3
1
1
0
2
00
11
5
01010
00111

样例输出 1

0
2
6

数据范围与提示

For the second sample test case, there are two valid operation pairs: and .

For the third sample test case, there are six valid operation pairs: , , , , and .