Under construction

Still being built. Things may change

01tree

Time limit1sMemory limit2048 MB

Summary
Given a tree of 0/1 node values with partial start and end states, sum the minimum flip counts over all consistent state pairs, modulo 1e9+7.
Level

Hard9 of 10

Topics
Tree, Dynamic programming, Combinatorics
Solved
No attempts yet

Problem

There is a tree with nn nodes. Every node has a value of 0 or 1.

In one second, you can choose two adjacent nodes with the same value and flip both values.

You always spend the least number of seconds to transform a starting state into an ending state. If it is impossible to transform the starting state into the ending state, you skip it (so you spend 0 seconds).

The catch is that for some nodes, you do not remember the value (in the starting state, the ending state, or both). Over all pairs of (starting state, ending state) that agree with your memory, find the total time it takes to transform the starting state into the ending state. Print this value modulo 109+710^9+7.

Input

The first line contains an integer tt, the number of test cases (1≤t≤10001 \le t \le 1000). The test cases follow.

The first line of each test case contains one integer nn (2≤n≤1052 \le n \le 10^5), the size of the tree.

Then n−1n-1 lines follow, each containing two integers uu and vv, denoting an edge that connects uu and vv in the tree.

The next line contains a string ss of length nn made of the characters 0, 1, and ?. This string is your memory of the starting state: 0 and 1 are the values of the nodes, and ? means you do not remember the value of that node.

The following line contains a string tt of length nn denoting your memory of the ending state, in the same format as the starting state.

The sum of nn over all test cases does not exceed 10510^5.

Output

For each test case, print one line with a single integer: the answer modulo 109+710^9+7.

Examples1

  1. Example 1

    Input
    3
    2
    1 2
    00
    11
    3
    1 2
    2 3
    ???
    ???
    3
    1 2
    2 3
    ??1
    0?0
    
    Expected output
    1
    16
    1