**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Sakurako's Hobby
time_limit_ms: 2000
memory_limit_mb: 256
Description: For a certain permutation $p$$^{\text{∗}}$ Sakurako calls an integer $j$ reachable from an integer $i$ if it is possible to make $i$ equal to $j$ by assigning $i=p_i$ a certain number of times.

If $p=[3,5,6,1,2,4]$, then, for example, $4$ is reachable from $1$, because: $i=1$ $\rightarrow$ $i=p_1=3$ $\rightarrow$ $i=p_3=6$ $\rightarrow$ $i=p_6=4$. Now $i=4$, so $4$ is reachable from $1$.

Each number in the permutation is colored either black or white.

Sakurako defines the function $F(i)$ as the number of black integers that are reachable from $i$.

Sakurako is interested in $F(i)$ for each $1\le i\le n$, but calculating all values becomes very difficult, so she asks you, as her good friend, to compute this.

$^{\text{∗}}$A permutation of length $n$ is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation (the number $2$ appears twice in the array), and $[1,3,4]$ is also not a permutation ($n=3$, but the array contains $4$).

Input: The first line contains a single integer $t$ ($1\le t\le 10^4$)  — the number of test cases.

The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$)  — the number of elements in the array.

The second line of each test case contains $n$ integers $p_1, p_2, \dots, p_n$ ($1\le p_i\le n$)  — the elements of the permutation.

The third line of each test case contains a string $s$ of length $n$, consisting of '0' and '1'. If $s_i=0$, then the number $p_i$ is colored black; if $s_i=1$, then the number $p_i$ is colored white.

It is guaranteed that the sum of $n$ across all test cases does not exceed $2\cdot 10^5$.

Output: For each test case, output $n$ integers $F(1), F(2), \dots, F(n)$.

Examples:
input:
5
1
1
0
5
1 2 4 5 3
10101
5
5 4 1 3 2
10011
6
3 5 6 1 2 4
010000
6
1 2 3 4 5 6
100110
output:
1
0 1 1 1 1
2 2 2 2 2
4 1 4 4 1 4
0 1 1 0 0 1

Note:

Buggy Code:
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int main() {
    int t;
    cin>>t;
    for(int i=0;i<t;i++){
        int n;
        cin>>n;
        vector<int> v;
        for(int j=0;j<n;j++){
            int a;
            cin>>a;
            v.push_back(a);
        }
        string s;
        cin>>s;
        for(int j=0;j<n;j++){
            int f=0,k=j;
            vector<int> w(n,0);
            while(true){
                if(w[k]==0){
                    w[k]=1;
                    if(s[k]=='0'){
                        f++;
                    }
                    k=v[k]-1;
                }
                else{
                    cout<<f<<" ";
                    break;
                }
            }
        }
        cout<<"\n";
    }
}

**Instructions:**
- Focus on edge cases or scenarios that maximize the failure probability in faulty solutions.
- Due to the output length limit, you should generate a **small-scale** test input that is **complete and valid**.
- Output the test input directly, not code to generate it.

**Output format:**
```plaintext
{test input}
```

Think step by step.

Response:
To generate a challenging test input that exposes the bug in the given buggy code, we need to consider the following:

1. **Cycle Detection**: The buggy code might fail if it doesn't properly handle cycles in the permutation. Each element in the permutation can lead to a cycle, and the code should correctly track which elements have been visited to avoid infinite loops.

2. **Color Tracking**: The code should correctly count the number of black elements (denoted by '0') that are reachable from each starting point. If the code doesn't handle the visited elements properly, it might count the same elements multiple times or miss some.

3. **Edge Cases**: Small permutations with specific patterns can help in exposing the bug. For example, a permutation that forms a single cycle or multiple disjoint cycles.

Let's create a test case that includes a permutation with a cycle and mixed colors to ensure the code handles it correctly.

### Test Case
```plaintext
1
6
3 5 6 1 2 4
010000
```

### Explanation
- **Permutation**: `[3, 5, 6, 1, 2, 4]`
  - This permutation forms a single cycle: `1 -> 3 -> 6 -> 4 -> 1`.
  - Starting from any element in this cycle, you will eventually visit all elements in the cycle.
- **Colors**: `010000`
  - The elements 3, 6, and 4 are black (0), and the elements 5, 1, and 2 are white (1).

### Expected Output
- **F(1)**: 4 (reachable black elements: 3, 6, 4)
- **F(2)**: 1 (reachable black element: 5)
- **F(3)**: 4 (reachable black elements: 6, 4, 3)
- **F(4)**: 4 (reachable black elements: 1, 3, 6)
- **F(5)**: 1 (reachable black element: 2)
- **F(6)**: 4 (reachable black elements: 4, 3, 6)

This test case should help in exposing any issues with cycle detection and color tracking in the buggy code.


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Sakurako's Hobby
time_limit_ms: 2000
memory_limit_mb: 256
Description: For a certain permutation $p$$^{\text{∗}}$ Sakurako calls an integer $j$ reachable from an integer $i$ if it is possible to make $i$ equal to $j$ by assigning $i=p_i$ a certain number of times.

If $p=[3,5,6,1,2,4]$, then, for example, $4$ is reachable from $1$, because: $i=1$ $\rightarrow$ $i=p_1=3$ $\rightarrow$ $i=p_3=6$ $\rightarrow$ $i=p_6=4$. Now $i=4$, so $4$ is reachable from $1$.

Each number in the permutation is colored either black or white.

Sakurako defines the function $F(i)$ as the number of black integers that are reachable from $i$.

Sakurako is interested in $F(i)$ for each $1\le i\le n$, but calculating all values becomes very difficult, so she asks you, as her good friend, to compute this.

$^{\text{∗}}$A permutation of length $n$ is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation (the number $2$ appears twice in the array), and $[1,3,4]$ is also not a permutation ($n=3$, but the array contains $4$).

Input: The first line contains a single integer $t$ ($1\le t\le 10^4$)  — the number of test cases.

The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$)  — the number of elements in the array.

The second line of each test case contains $n$ integers $p_1, p_2, \dots, p_n$ ($1\le p_i\le n$)  — the elements of the permutation.

The third line of each test case contains a string $s$ of length $n$, consisting of '0' and '1'. If $s_i=0$, then the number $p_i$ is colored black; if $s_i=1$, then the number $p_i$ is colored white.

It is guaranteed that the sum of $n$ across all test cases does not exceed $2\cdot 10^5$.

Output: For each test case, output $n$ integers $F(1), F(2), \dots, F(n)$.

Examples:
input:
5
1
1
0
5
1 2 4 5 3
10101
5
5 4 1 3 2
10011
6
3 5 6 1 2 4
010000
6
1 2 3 4 5 6
100110
output:
1
0 1 1 1 1
2 2 2 2 2
4 1 4 4 1 4
0 1 1 0 0 1

Note:

Buggy Code:
import sys
import threading
threading.stack_size(50000000)
sys.setrecursionlimit(20000)
def count(idxnode,visited,first,snt):
    if idxnode not in visited:
        head[idxnode]=first
        visited.add(idxnode)
        if str[idxnode]=='0':
           return count(arr[idxnode],visited,first,snt+1)
        else:
            return count(arr[idxnode],visited,first,snt)
    return snt
def setup_array(n):
    global arr  # Declare that we are modifying the global array
    global head  # Declare that we are modifying the global array
    arr = [0] * (n + 1)
    head = [0] * (n + 1)
def setup_str(n):
    global str  # Declare that we are modifying the global array
    str = ['s'for _ in range(n+1)]

def main():
    t = int(input())

    while t != 0:
        n = int(input())
        fake = list(map(int, input().split()))
        fakestr = input().strip()
        setup_array(n)
        setup_str(n)
        for i in range(n):
            arr[i + 1] = fake[i]
            str[i + 1] = fakestr[i]
        cnt = [0] * (n + 1)
        visited = set()

        for i in range(1, n + 1):
            if i not in visited:
                cnt[i] = count(i, visited, i, 0)

        for i in range(1, n + 1):
            print(cnt[head[i]], end=' ')

        print()
        t -= 1

thread = threading.Thread(target=main)
thread.start()
thread.join()

**Instructions:**
- Focus on edge cases or scenarios that maximize the failure probability in faulty solutions.
- Due to the output length limit, you should generate a **small-scale** test input that is **complete and valid**.
- Output the test input directly, not code to generate it.

**Output format:**
```plaintext
{test input}
```

Think step by step.

Response:
To expose the bug in the provided buggy code, we need to focus on edge cases and scenarios that can highlight issues in the algorithm. Here are the steps to consider:

1. **Cycle Detection**: The code should correctly handle cycles in the permutation.
2. **Coloring**: The code should correctly count the number of black integers reachable from each starting point.
3. **Visited Set**: The code should ensure that each node is visited only once to avoid infinite loops.

A good test case to expose potential issues is a permutation with a cycle and a mix of black and white colors. Here is a small-scale test input that can help expose the bug:

```plaintext
1
6
3 5 6 1 2 4
010000
```

Explanation:
- The permutation is `[3, 5, 6, 1, 2, 4]`.
- The colors are `010000`, which means the integers 3, 4, 5, and 6 are black, and 1 and 2 are white.
- This permutation has a cycle: `1 -> 3 -> 6 -> 4 -> 1`.

The expected output for this test case is:
```
4 1 4 4 1 4
```

This test case will help verify if the code correctly handles cycles and counts the number of black integers reachable from each starting point.


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Sakurako's Hobby
time_limit_ms: 2000
memory_limit_mb: 256
Description: For a certain permutation $p$$^{\text{∗}}$ Sakurako calls an integer $j$ reachable from an integer $i$ if it is possible to make $i$ equal to $j$ by assigning $i=p_i$ a certain number of times.

If $p=[3,5,6,1,2,4]$, then, for example, $4$ is reachable from $1$, because: $i=1$ $\rightarrow$ $i=p_1=3$ $\rightarrow$ $i=p_3=6$ $\rightarrow$ $i=p_6=4$. Now $i=4$, so $4$ is reachable from $1$.

Each number in the permutation is colored either black or white.

Sakurako defines the function $F(i)$ as the number of black integers that are reachable from $i$.

Sakurako is interested in $F(i)$ for each $1\le i\le n$, but calculating all values becomes very difficult, so she asks you, as her good friend, to compute this.

$^{\text{∗}}$A permutation of length $n$ is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation (the number $2$ appears twice in the array), and $[1,3,4]$ is also not a permutation ($n=3$, but the array contains $4$).

Input: The first line contains a single integer $t$ ($1\le t\le 10^4$)  — the number of test cases.

The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$)  — the number of elements in the array.

The second line of each test case contains $n$ integers $p_1, p_2, \dots, p_n$ ($1\le p_i\le n$)  — the elements of the permutation.

The third line of each test case contains a string $s$ of length $n$, consisting of '0' and '1'. If $s_i=0$, then the number $p_i$ is colored black; if $s_i=1$, then the number $p_i$ is colored white.

It is guaranteed that the sum of $n$ across all test cases does not exceed $2\cdot 10^5$.

Output: For each test case, output $n$ integers $F(1), F(2), \dots, F(n)$.

Examples:
input:
5
1
1
0
5
1 2 4 5 3
10101
5
5 4 1 3 2
10011
6
3 5 6 1 2 4
010000
6
1 2 3 4 5 6
100110
output:
1
0 1 1 1 1
2 2 2 2 2
4 1 4 4 1 4
0 1 1 0 0 1

Note:

Buggy Code:
loop = int(input())

for i in range (loop):
    permNum = int(input())
    elementsLine = input()
    elements = list(map(int, list(elementsLine.split(" "))))
    blackwhite = [j for j in input()]
    check = []

    for m in range(permNum):
        check.append(-1)

    for element in elements:
        blackCount = 0
        x = element
        checked = []
        while True:
            x = elements[x-1]

            if elements.index(x) < elements.index(element):
                blackCount = check[elements.index(x)]
                break

            if blackwhite[elements.index(x)] == '0':
                blackCount = blackCount +  1

            if x == element or x in checked:
                break

            checked.append(x)

        check[elements.index(element)] = (blackCount)

    print(*check)

**Instructions:**
- Focus on edge cases or scenarios that maximize the failure probability in faulty solutions.
- Due to the output length limit, you should generate a **small-scale** test input that is **complete and valid**.
- Output the test input directly, not code to generate it.

**Output format:**
```plaintext
{test input}
```

Think step by step.

Response:
```plaintext
5
1
1
0
3
1 2 3
101
3
3 1 2
010
4
4 1 3 2
1010
4
1 3 2 4
0110
```


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Sakurako's Hobby
time_limit_ms: 2000
memory_limit_mb: 256
Description: For a certain permutation $p$$^{\text{∗}}$ Sakurako calls an integer $j$ reachable from an integer $i$ if it is possible to make $i$ equal to $j$ by assigning $i=p_i$ a certain number of times.

If $p=[3,5,6,1,2,4]$, then, for example, $4$ is reachable from $1$, because: $i=1$ $\rightarrow$ $i=p_1=3$ $\rightarrow$ $i=p_3=6$ $\rightarrow$ $i=p_6=4$. Now $i=4$, so $4$ is reachable from $1$.

Each number in the permutation is colored either black or white.

Sakurako defines the function $F(i)$ as the number of black integers that are reachable from $i$.

Sakurako is interested in $F(i)$ for each $1\le i\le n$, but calculating all values becomes very difficult, so she asks you, as her good friend, to compute this.

$^{\text{∗}}$A permutation of length $n$ is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation (the number $2$ appears twice in the array), and $[1,3,4]$ is also not a permutation ($n=3$, but the array contains $4$).

Input: The first line contains a single integer $t$ ($1\le t\le 10^4$)  — the number of test cases.

The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$)  — the number of elements in the array.

The second line of each test case contains $n$ integers $p_1, p_2, \dots, p_n$ ($1\le p_i\le n$)  — the elements of the permutation.

The third line of each test case contains a string $s$ of length $n$, consisting of '0' and '1'. If $s_i=0$, then the number $p_i$ is colored black; if $s_i=1$, then the number $p_i$ is colored white.

It is guaranteed that the sum of $n$ across all test cases does not exceed $2\cdot 10^5$.

Output: For each test case, output $n$ integers $F(1), F(2), \dots, F(n)$.

Examples:
input:
5
1
1
0
5
1 2 4 5 3
10101
5
5 4 1 3 2
10011
6
3 5 6 1 2 4
010000
6
1 2 3 4 5 6
100110
output:
1
0 1 1 1 1
2 2 2 2 2
4 1 4 4 1 4
0 1 1 0 0 1

Note:

Buggy Code:
import java.util.*;
public final class Main
{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int t=sc.nextInt();
		while(t-->0){
		  int n=sc.nextInt();
		  int arr[]=new int[n];
		  for(int i=0;i<n;i++){
		      arr[i]=sc.nextInt()-1;
		  }
		  String s=sc.next();
		  int ans[]=new int[n];
		  for(int i=0;i<n;i++){

		      if(s.charAt(i)=='0'){
		      int j=i;
		      while(true){

		          j=arr[j];
		          ans[j]+=1;
		          if(i==j){
		              break;
		          }
		      }
		      }

		  }

		  for(int i=0;i<n;i++){
		      System.out.print(ans[i]+" ");
		  }
		  System.out.println();

		}
	}
}

**Instructions:**
- Focus on edge cases or scenarios that maximize the failure probability in faulty solutions.
- Due to the output length limit, you should generate a **small-scale** test input that is **complete and valid**.
- Output the test input directly, not code to generate it.

**Output format:**
```plaintext
{test input}
```

Think step by step.

Response:
To generate a challenging test input that exposes the bug in the provided buggy code, we need to focus on edge cases and scenarios that can cause the code to fail. Let's analyze the code and identify potential issues:

1. **Infinite Loops**: The code uses a `while(true)` loop to traverse the permutation. If the permutation has cycles, the loop can run indefinitely unless it breaks correctly.
2. **Cycle Detection**: The code breaks the loop when `i == j`, which might not be the correct condition to detect all cycles.
3. **Incorrect Counting**: The code increments `ans[j]` for each step in the cycle, which might lead to incorrect counts if the cycle is not handled properly.

To expose these issues, we can create a test case with a permutation that has a cycle and ensure that the cycle includes both black and white elements. This will test how the code handles cycles and counting.

Here is a small-scale test input that should expose the bug:

```plaintext
1
6
3 5 6 1 2 4
010000
```

Explanation:
- **Permutation**: `[3, 5, 6, 1, 2, 4]`
- **Colors**: `010000` (Black: 3, 6; White: 5, 1, 2, 4)
- **Cycle**: Starting from index 0 (value 3), the cycle is `3 -> 6 -> 4 -> 1 -> 3`.
- **Expected Output**: `4 1 4 4 1 4`

This test case will ensure that the code correctly handles the cycle and counts the number of black integers reachable from each starting point. If the code fails to detect the cycle correctly or counts incorrectly, this test case should expose the bug.


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Sakurako's Hobby
time_limit_ms: 2000
memory_limit_mb: 256
Description: For a certain permutation $p$$^{\text{∗}}$ Sakurako calls an integer $j$ reachable from an integer $i$ if it is possible to make $i$ equal to $j$ by assigning $i=p_i$ a certain number of times.

If $p=[3,5,6,1,2,4]$, then, for example, $4$ is reachable from $1$, because: $i=1$ $\rightarrow$ $i=p_1=3$ $\rightarrow$ $i=p_3=6$ $\rightarrow$ $i=p_6=4$. Now $i=4$, so $4$ is reachable from $1$.

Each number in the permutation is colored either black or white.

Sakurako defines the function $F(i)$ as the number of black integers that are reachable from $i$.

Sakurako is interested in $F(i)$ for each $1\le i\le n$, but calculating all values becomes very difficult, so she asks you, as her good friend, to compute this.

$^{\text{∗}}$A permutation of length $n$ is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation (the number $2$ appears twice in the array), and $[1,3,4]$ is also not a permutation ($n=3$, but the array contains $4$).

Input: The first line contains a single integer $t$ ($1\le t\le 10^4$)  — the number of test cases.

The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$)  — the number of elements in the array.

The second line of each test case contains $n$ integers $p_1, p_2, \dots, p_n$ ($1\le p_i\le n$)  — the elements of the permutation.

The third line of each test case contains a string $s$ of length $n$, consisting of '0' and '1'. If $s_i=0$, then the number $p_i$ is colored black; if $s_i=1$, then the number $p_i$ is colored white.

It is guaranteed that the sum of $n$ across all test cases does not exceed $2\cdot 10^5$.

Output: For each test case, output $n$ integers $F(1), F(2), \dots, F(n)$.

Examples:
input:
5
1
1
0
5
1 2 4 5 3
10101
5
5 4 1 3 2
10011
6
3 5 6 1 2 4
010000
6
1 2 3 4 5 6
100110
output:
1
0 1 1 1 1
2 2 2 2 2
4 1 4 4 1 4
0 1 1 0 0 1

Note:

Buggy Code:
import java.io.*;
import java.util.StringTokenizer;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.HashSet;
import java.util.Set;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(System.out);

		StringTokenizer st = new StringTokenizer(r.readLine());
		int t = Integer.parseInt(st.nextToken());
		for (int test = 0; test < t; test++) {
			st = new StringTokenizer(r.readLine());
			int num = Integer.parseInt(st.nextToken());
			Dictionary<Integer, String> dict= new Hashtable<>();
			st = new StringTokenizer(r.readLine());
			int[] arr = new int[num];
			int temp;
			for (int a = 0; a < num; a++) {
				temp = Integer.parseInt(st.nextToken());
				arr[a] = temp;
			}
			st = new StringTokenizer(r.readLine());
			String s = st.nextToken();
			for (int a = 0; a < num; a++) {
				dict.put(arr[a], s.substring(a, a+1));
			}
			for (int a = 0; a < num; a++) {
				Set<Integer> set = new HashSet<>();
				int next = arr[a];
				int count = 0;
				while (!set.contains(next)) {
					set.add(next);
					if (dict.get(next).equals("0")) {
						count++;
					}
					next = arr[next-1];
				}
				pw.print(count + " ");
			}
			pw.println();
		}

		pw.close();
	}
}

**Instructions:**
- Focus on edge cases or scenarios that maximize the failure probability in faulty solutions.
- Due to the output length limit, you should generate a **small-scale** test input that is **complete and valid**.
- Output the test input directly, not code to generate it.

**Output format:**
```plaintext
{test input}
```

Think step by step.

Response:
```plaintext
5
1
1
0
5
1 2 3 4 5
11111
5
5 4 3 2 1
00000
5
1 2 3 4 5
01010
6
6 1 2 3 4 5
101010
```


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Reconstruction
time_limit_ms: 2000
memory_limit_mb: 256
Description: There is a hidden array $a_1, a_2, \ldots, a_n$ of length $n$ whose elements are integers between $-m$ and $m$, inclusive.

You are given an array $b_1, b_2, \ldots, b_n$ of length $n$ and a string $s$ of length $n$ consisting of the characters $\texttt{P}$, $\texttt{S}$, and $\texttt{?}$.

For each $i$ from $1$ to $n$ inclusive, we must have:

  * If $s_i = \texttt{P}$, $b_i$ is the sum of $a_1$ through $a_i$.    * If $s_i = \texttt{S}$, $b_i$ is the sum of $a_i$ through $a_n$.

Output the number of ways to replace all $\texttt{?}$ in $s$ with either $\texttt{P}$ or $\texttt{S}$ such that there exists an array $a_1, a_2, \ldots, a_n$ with elements not exceeding $m$ by absolute value satisfying the constraints given by the array $b_1, b_2, \ldots, b_n$ and the string $s$.

Since the answer may be large, output it modulo $998\,244\,353$.

Input: The first line contains a single integer $t$ ($1 \leq t \leq 10^3$) — the number of test cases.

The first line of each test case contains two integers $n$ and $m$ ($2 \leq n \leq 2 \cdot 10^3$, $2 \leq m \leq 10^{9}$) — the length of the hidden array $a_1, a_2, \ldots, a_n$ and the maximum absolute value of an element $a_i$.

The second line of each test case contains a string $s$ of length $n$ consisting of characters $\texttt{P}$, $\texttt{S}$, and $\texttt{?}$.

The third line of each test case contains $n$ integers $b_1, b_2, \ldots, b_n$ ($|b_i| \leq m \cdot n$).

The sum of $n$ over all test cases does not exceed $5 \cdot 10^3$.

Output: For each test case, output a single integer — the number of ways to replace all $\texttt{?}$ in $s$ with either $\texttt{P}$ or $\texttt{S}$ that result in the existence of a valid array $a_1, a_2, \ldots, a_n$, modulo $998\,244\,353$.

Examples:
input:
6
4 10
PSPP
1 9 8 10
4 1000000000
????
1 1 1 4000000000
8 1000000000
?P?SSP?P
-857095623 -1424391899 -851974476 673437144 471253851 -543483033 364945701 -178537332
4 7
PPSS
4 2 1 3
9 20
?????????
1 2 3 4 5 6 7 8 9
3 1000000000
P??
-145463248 -974068460 -1287458396
output:
1
0
2
1
14
1

Note: In the first test case, we can see that the following array satisfies all constraints, thus the answer is $1$:

  1. $\texttt{P}$ — ${[\color{red}{\textbf{1}},3,4,2]}$: sum of $1$.    2. $\texttt{S}$ — ${[1,\color{red}{\textbf{3},4,2}]}$: sum of $9$.    3. $\texttt{P}$ — ${[\color{red}{1,3,\textbf{4}},2]}$: sum of $8$.    4. $\texttt{P}$ — ${[\color{red}{1,3,4,\textbf{2}}]}$: sum of $10$.

In the second test case, it can be shown that no array $a$ with all $|a_i| \leq m = 10^9$ satisfies all constraints.

Buggy Code:
import sys,random,bisect
from collections import deque,defaultdict
from heapq import heapify,heappop,heappush
from itertools import permutations
from math import gcd,log

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

mod = 998244353

def solve(N,M,S,B):
    res = 0

    for sf in ("S","P"):
        if S[0]!='?' and S[0]!=sf:
            continue
        for sl in ("S","P"):
            if S[-1]!='?' and S[-1]!=sl:
                continue

            if sf == "S" and sl == "P" and B[0]!=B[-1]:
                continue

            whole_sum = None
            if sf == "S":
                whole_sum = B[0]
            if sl == "P":
                whole_sum = B[-1]

            if whole_sum is not None:
                dp = [0,0]
                if sf == 'S':
                    dp[0] = 1
                else:
                    if abs(B[0]) <= M:
                        dp[1] = 1

                for i in range(1,N-1):
                    ndp = [0,0]
                    if S[i] == '?' or S[i] == 'S':
                        if B[i-1] == whole_sum - B[i]:
                            ndp[0] += dp[1]
                        if abs(B[i]-B[i-1]) <= M:
                            ndp[0] += dp[0]
                    if S[i] == '?' or S[i] == 'P':
                        if abs(B[i]-B[i-1]) <= M:
                            ndp[1] += dp[1]
                        if abs(B[i]-(whole_sum-B[i-1])) <= 2*M:
                            ndp[1] += dp[0]
                    dp = [ndp[0] % mod, ndp[1] % mod]
                for _ in range(1):
                    i = N-1
                    ndp = [0,0]
                    if sl == 'S':
                        if B[i-1] == whole_sum - B[i]:
                            ndp[0] += dp[1]
                        if abs(B[i]-B[i-1]) <= M:
                            ndp[0] += dp[0]
                    if sl == 'P':
                        if abs(B[i]-B[i-1]) <= M:
                            ndp[1] += dp[1]
                        if abs(B[i]-(whole_sum-B[i-1])) <= 2*M:
                            ndp[1] += dp[0]
                    dp = [ndp[0] % mod, ndp[1] % mod]

                if sl == 'S':
                    if abs(B[-1]) > M:
                        continue

                res += sum(dp) % mod
                res %= mod
                continue

            pre = 0
            for i in range(N-1):
                if abs(B[i]-pre) > M:
                    break
                pre = B[i]

                whole_sum = B[i] + B[i+1]
                if abs(whole_sum-(whole_sum-B[-1])) > M:
                    continue
                if S[i] == 'S' or S[i+1] == 'P':
                    continue

                dp = [0,0]
                dp[1] = 1

                for j in range(i+1,N):
                    ndp = [0,0]
                    if j == i+1:
                        a = "S"
                    elif j == N-1:
                        a = "S"
                    else:
                        a = S[j]
                    if a == '?' or a == 'S':
                        if B[j-1] == whole_sum - B[j]:
                            ndp[0] += dp[1]
                        if abs(B[j]-B[j-1]) <= M:
                            ndp[0] += dp[0]
                    if a == '?' or a == 'P':
                        if abs(B[j]-B[j-1]) <= M:
                            ndp[1] += dp[1]
                        if abs(B[j]-(whole_sum-B[j-1])) <= 2*M:
                            ndp[1] += dp[0]
                    dp = [ndp[0] % mod, ndp[1] % mod]

                #print(i,dp)
                res += sum(dp) % mod
                res %= mod

    return res

def brute(N,M,S,B):
    ans = 0
    for T in range(1<<N):
        T = "".join(["S" if T>>i & 1 else "P" for i in range(N)])
        flg = 0
        for i in range(N):
            if T[i]!='?' and S[i]!='?' and T[i]!=S[i]:
                flg = 1
        if flg:
            continue

        whole_sum = None
        if T[0]=="S":
            whole_sum = B[0]
        if T[-1]=="P":
            whole_sum = B[-1]

        for i in range(N-1):
            if T[i]=="P" and T[i+1]=="S":
                whole_sum = B[i] + B[i+1]

        prefix_sum = [None] * (N+1)
        prefix_sum[0] = 0
        prefix_sum[N] = whole_sum
        for i in range(N):
            if T[i] == "P":
                if prefix_sum[i+1] is None:
                    prefix_sum[i+1] = B[i]
                else:
                    if prefix_sum[i+1]!=B[i]:
                        break
            else:
                if prefix_sum[i] is None:
                    prefix_sum[i] = whole_sum - B[i]
                else:
                    if prefix_sum[i]!= whole_sum - B[i]:
                        break
        else:
            #print(T)
            pre = 0
            for i in range(1,N+1):
                if prefix_sum[i] is None:
                    continue

                check = prefix_sum[i] - prefix_sum[pre]
                if abs(check) > M * (i-pre):
                    break
                pre = i
            else:
                #print(T)
                ans += 1

    return ans

def make_test(N,M):
    S = '?' * N
    A = [random.randint(-M,M) for i in range(N)]
    cum = [0] * (N+1)
    for i in range(N):
        cum[i+1] = cum[i] + A[i]

    B = []
    for i in range(N):
        if random.randint(0,99) & 1:
            B.append(cum[i+1])
        else:
            B.append(cum[N]-cum[i])

    return S,B

while False:
    N,M = random.randint(2,10),random.randint(0,100)
    S,B = make_test(N,M)

    #S = '??'
    #B = [-2,-4]

    res = solve(N,M,S,B)
    exp = brute(N,M,S,B)
    if res!=exp:
        print("WA")
        print(N,M)
        print(S)
        print(B)
        print(res,exp)
        exit()
    else:
        print("AC",B,exp)

for _ in range(int(input())):
    N,M = mi()
    S = input()
    B = li()
    print(solve(N,M,S,B))

**Instructions:**
- Focus on edge cases or scenarios that maximize the failure probability in faulty solutions.
- Due to the output length limit, you should generate a **small-scale** test input that is **complete and valid**.
- Output the test input directly, not code to generate it.

**Output format:**
```plaintext
{test input}
```

Think step by step.

Response:
```plaintext
4 10
????
10 10 10 10
```


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Reconstruction
time_limit_ms: 2000
memory_limit_mb: 256
Description: There is a hidden array $a_1, a_2, \ldots, a_n$ of length $n$ whose elements are integers between $-m$ and $m$, inclusive.

You are given an array $b_1, b_2, \ldots, b_n$ of length $n$ and a string $s$ of length $n$ consisting of the characters $\texttt{P}$, $\texttt{S}$, and $\texttt{?}$.

For each $i$ from $1$ to $n$ inclusive, we must have:

  * If $s_i = \texttt{P}$, $b_i$ is the sum of $a_1$ through $a_i$.    * If $s_i = \texttt{S}$, $b_i$ is the sum of $a_i$ through $a_n$.

Output the number of ways to replace all $\texttt{?}$ in $s$ with either $\texttt{P}$ or $\texttt{S}$ such that there exists an array $a_1, a_2, \ldots, a_n$ with elements not exceeding $m$ by absolute value satisfying the constraints given by the array $b_1, b_2, \ldots, b_n$ and the string $s$.

Since the answer may be large, output it modulo $998\,244\,353$.

Input: The first line contains a single integer $t$ ($1 \leq t \leq 10^3$) — the number of test cases.

The first line of each test case contains two integers $n$ and $m$ ($2 \leq n \leq 2 \cdot 10^3$, $2 \leq m \leq 10^{9}$) — the length of the hidden array $a_1, a_2, \ldots, a_n$ and the maximum absolute value of an element $a_i$.

The second line of each test case contains a string $s$ of length $n$ consisting of characters $\texttt{P}$, $\texttt{S}$, and $\texttt{?}$.

The third line of each test case contains $n$ integers $b_1, b_2, \ldots, b_n$ ($|b_i| \leq m \cdot n$).

The sum of $n$ over all test cases does not exceed $5 \cdot 10^3$.

Output: For each test case, output a single integer — the number of ways to replace all $\texttt{?}$ in $s$ with either $\texttt{P}$ or $\texttt{S}$ that result in the existence of a valid array $a_1, a_2, \ldots, a_n$, modulo $998\,244\,353$.

Examples:
input:
6
4 10
PSPP
1 9 8 10
4 1000000000
????
1 1 1 4000000000
8 1000000000
?P?SSP?P
-857095623 -1424391899 -851974476 673437144 471253851 -543483033 364945701 -178537332
4 7
PPSS
4 2 1 3
9 20
?????????
1 2 3 4 5 6 7 8 9
3 1000000000
P??
-145463248 -974068460 -1287458396
output:
1
0
2
1
14
1

Note: In the first test case, we can see that the following array satisfies all constraints, thus the answer is $1$:

  1. $\texttt{P}$ — ${[\color{red}{\textbf{1}},3,4,2]}$: sum of $1$.    2. $\texttt{S}$ — ${[1,\color{red}{\textbf{3},4,2}]}$: sum of $9$.    3. $\texttt{P}$ — ${[\color{red}{1,3,\textbf{4}},2]}$: sum of $8$.    4. $\texttt{P}$ — ${[\color{red}{1,3,4,\textbf{2}}]}$: sum of $10$.

In the second test case, it can be shown that no array $a$ with all $|a_i| \leq m = 10^9$ satisfies all constraints.

Buggy Code:
#include <bits/stdc++.h>
using namespace std;
namespace Le0{
#define LL long long
const int N=2e3+5,mod=998244353;
int T,n,m,ans;
LL b[N];
bool vis[N],vis2[N];
int f[N][2];
string s;
int work(string t,int sm,int id){
    f[1][0]=(t[1]=='S');
    f[1][1]=(t[1]=='P');
    for(int i=2;i<=n;i++){
        f[i][0]=f[i][1]=0;
        if(t[i]!='P'){
            f[i][0]+=f[i-1][0]*(abs(b[i]-b[i-1])<=m),f[i][0]%=mod;
            f[i][0]+=f[i-1][1]*(b[i]+b[i-1]==sm),f[i][0]%=mod;
        }
        if(t[i]!='S'){
            f[i][1]+=f[i-1][1]*(abs(b[i]-b[i-1])<=m),f[i][1]%=mod;
            if(i>=id)
            f[i][1]+=f[i-1][0]*(abs(b[i]+b[i-1]-sm)<=m),f[i][1]%=mod;
        }
    }
    return (f[n][0]+f[n][1])%mod;
}
int main(){
    cin>>T;
    while(T--){
        ans=0;
        cin>>n>>m>>s;
        n+=2;
        s=" P"+s+"S";
        b[1]=0;
        for(int i=2;i<n;i++) cin>>b[i];
        b[n]=0;
        bool ok=0;
        for(int id=2;id<=n;id++){
            if(s[id-1]=='S'||s[id]=='P') continue;
            string t=s;
            t[id-1]='P';t[id]='S';
            int sm=b[id]+b[id-1];
            ans=(ans+work(t,sm,id));
            if(s[id]=='S'&&s[id-1]=='P') {ok=1;break;}
        }
        cout<<ans<<'\n';
    }
    return 0;
}
}
int main(){
    ios::sync_with_stdio(0),cin.tie(0);
    return Le0::main();
}

**Instructions:**
- Focus on edge cases or scenarios that maximize the failure probability in faulty solutions.
- Due to the output length limit, you should generate a **small-scale** test input that is **complete and valid**.
- Output the test input directly, not code to generate it.

**Output format:**
```plaintext
{test input}
```

Think step by step.

Response:
```plaintext
1
4 10
P??S
1 9 8 10
```


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Reconstruction
time_limit_ms: 2000
memory_limit_mb: 256
Description: There is a hidden array $a_1, a_2, \ldots, a_n$ of length $n$ whose elements are integers between $-m$ and $m$, inclusive.

You are given an array $b_1, b_2, \ldots, b_n$ of length $n$ and a string $s$ of length $n$ consisting of the characters $\texttt{P}$, $\texttt{S}$, and $\texttt{?}$.

For each $i$ from $1$ to $n$ inclusive, we must have:

  * If $s_i = \texttt{P}$, $b_i$ is the sum of $a_1$ through $a_i$.    * If $s_i = \texttt{S}$, $b_i$ is the sum of $a_i$ through $a_n$.

Output the number of ways to replace all $\texttt{?}$ in $s$ with either $\texttt{P}$ or $\texttt{S}$ such that there exists an array $a_1, a_2, \ldots, a_n$ with elements not exceeding $m$ by absolute value satisfying the constraints given by the array $b_1, b_2, \ldots, b_n$ and the string $s$.

Since the answer may be large, output it modulo $998\,244\,353$.

Input: The first line contains a single integer $t$ ($1 \leq t \leq 10^3$) — the number of test cases.

The first line of each test case contains two integers $n$ and $m$ ($2 \leq n \leq 2 \cdot 10^3$, $2 \leq m \leq 10^{9}$) — the length of the hidden array $a_1, a_2, \ldots, a_n$ and the maximum absolute value of an element $a_i$.

The second line of each test case contains a string $s$ of length $n$ consisting of characters $\texttt{P}$, $\texttt{S}$, and $\texttt{?}$.

The third line of each test case contains $n$ integers $b_1, b_2, \ldots, b_n$ ($|b_i| \leq m \cdot n$).

The sum of $n$ over all test cases does not exceed $5 \cdot 10^3$.

Output: For each test case, output a single integer — the number of ways to replace all $\texttt{?}$ in $s$ with either $\texttt{P}$ or $\texttt{S}$ that result in the existence of a valid array $a_1, a_2, \ldots, a_n$, modulo $998\,244\,353$.

Examples:
input:
6
4 10
PSPP
1 9 8 10
4 1000000000
????
1 1 1 4000000000
8 1000000000
?P?SSP?P
-857095623 -1424391899 -851974476 673437144 471253851 -543483033 364945701 -178537332
4 7
PPSS
4 2 1 3
9 20
?????????
1 2 3 4 5 6 7 8 9
3 1000000000
P??
-145463248 -974068460 -1287458396
output:
1
0
2
1
14
1

Note: In the first test case, we can see that the following array satisfies all constraints, thus the answer is $1$:

  1. $\texttt{P}$ — ${[\color{red}{\textbf{1}},3,4,2]}$: sum of $1$.    2. $\texttt{S}$ — ${[1,\color{red}{\textbf{3},4,2}]}$: sum of $9$.    3. $\texttt{P}$ — ${[\color{red}{1,3,\textbf{4}},2]}$: sum of $8$.    4. $\texttt{P}$ — ${[\color{red}{1,3,4,\textbf{2}}]}$: sum of $10$.

In the second test case, it can be shown that no array $a$ with all $|a_i| \leq m = 10^9$ satisfies all constraints.

Buggy Code:
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<ll,int>
#define fi first
#define se second
#define mk make_pair
using namespace std;
ll read(){
	ll X = 0,r = 1;
	char ch = getchar();
	while(!isdigit(ch) && ch != '-') ch = getchar();
	if(ch == '-') r = -1,ch = getchar();
	while(isdigit(ch)) X = X*10+ch-'0',ch = getchar();
	return X*r;
}
const int N = 2e3+10;
const int mod = 998244353;
int n,m,tot;
char ch[N];
ll b[N],ans;
ll dp[N][2];
inline void work(ll sum){
	dp[0][0] = 1;
	for(int i=1;i<=n+1;i++) dp[i][0] = dp[i][1] = 0;
	for(int i=1;i<=n+1;i++){
		int st = 0;
		if(ch[i] == 'P') st = 1;
		else if(ch[i] == 'S') st = 2;
		else st = 3;
		if(st & 1){
			dp[i][0] = (dp[i][0]+(abs(b[i]-b[i-1]) <= m)*dp[i-1][0])%mod;
			dp[i][0] = (dp[i][0]+(abs(b[i]+b[i-1]) <= 2*m)*dp[i-1][1])%mod;
		}
		if(st & 2){
			dp[i][1] = (dp[i][1]+(b[i]+b[i-1] == sum)*dp[i-1][0])%mod;
			dp[i][1] = (dp[i][1]+(abs(b[i-1]-b[i]) <= m)*dp[i-1][1])%mod;
		}
	}
	ans = (ans+dp[n+1][0]+dp[n+1][1])%mod;
}
ll sum[N];
int main(){
	int T = read();
	while(T--){
		n = read(); m = read();
		cin >> ch+1;
		for(int i=1;i<=n;i++) b[i] = read();
		b[0] = b[n+1] = 0;
		ch[0] = 'P'; ch[n+1] = 'S';
		for(int i=1;i<=n+1;i++) sum[++tot] = b[i]+b[i-1];
		sort(sum+1,sum+1+tot);
		tot = unique(sum+1,sum+1+tot)-sum-1;
		ans = 0;
		for(int i=1;i<=tot;i++) work(sum[i]);
		cout << ans << "\n";
	}
	return 0;
}

**Instructions:**
- Focus on edge cases or scenarios that maximize the failure probability in faulty solutions.
- Due to the output length limit, you should generate a **small-scale** test input that is **complete and valid**.
- Output the test input directly, not code to generate it.

**Output format:**
```plaintext
{test input}
```

Think step by step.

Response:
```plaintext
1
4 2
P?P?
2 2 2 2
```


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Reconstruction
time_limit_ms: 2000
memory_limit_mb: 256
Description: There is a hidden array $a_1, a_2, \ldots, a_n$ of length $n$ whose elements are integers between $-m$ and $m$, inclusive.

You are given an array $b_1, b_2, \ldots, b_n$ of length $n$ and a string $s$ of length $n$ consisting of the characters $\texttt{P}$, $\texttt{S}$, and $\texttt{?}$.

For each $i$ from $1$ to $n$ inclusive, we must have:

  * If $s_i = \texttt{P}$, $b_i$ is the sum of $a_1$ through $a_i$.    * If $s_i = \texttt{S}$, $b_i$ is the sum of $a_i$ through $a_n$.

Output the number of ways to replace all $\texttt{?}$ in $s$ with either $\texttt{P}$ or $\texttt{S}$ such that there exists an array $a_1, a_2, \ldots, a_n$ with elements not exceeding $m$ by absolute value satisfying the constraints given by the array $b_1, b_2, \ldots, b_n$ and the string $s$.

Since the answer may be large, output it modulo $998\,244\,353$.

Input: The first line contains a single integer $t$ ($1 \leq t \leq 10^3$) — the number of test cases.

The first line of each test case contains two integers $n$ and $m$ ($2 \leq n \leq 2 \cdot 10^3$, $2 \leq m \leq 10^{9}$) — the length of the hidden array $a_1, a_2, \ldots, a_n$ and the maximum absolute value of an element $a_i$.

The second line of each test case contains a string $s$ of length $n$ consisting of characters $\texttt{P}$, $\texttt{S}$, and $\texttt{?}$.

The third line of each test case contains $n$ integers $b_1, b_2, \ldots, b_n$ ($|b_i| \leq m \cdot n$).

The sum of $n$ over all test cases does not exceed $5 \cdot 10^3$.

Output: For each test case, output a single integer — the number of ways to replace all $\texttt{?}$ in $s$ with either $\texttt{P}$ or $\texttt{S}$ that result in the existence of a valid array $a_1, a_2, \ldots, a_n$, modulo $998\,244\,353$.

Examples:
input:
6
4 10
PSPP
1 9 8 10
4 1000000000
????
1 1 1 4000000000
8 1000000000
?P?SSP?P
-857095623 -1424391899 -851974476 673437144 471253851 -543483033 364945701 -178537332
4 7
PPSS
4 2 1 3
9 20
?????????
1 2 3 4 5 6 7 8 9
3 1000000000
P??
-145463248 -974068460 -1287458396
output:
1
0
2
1
14
1

Note: In the first test case, we can see that the following array satisfies all constraints, thus the answer is $1$:

  1. $\texttt{P}$ — ${[\color{red}{\textbf{1}},3,4,2]}$: sum of $1$.    2. $\texttt{S}$ — ${[1,\color{red}{\textbf{3},4,2}]}$: sum of $9$.    3. $\texttt{P}$ — ${[\color{red}{1,3,\textbf{4}},2]}$: sum of $8$.    4. $\texttt{P}$ — ${[\color{red}{1,3,4,\textbf{2}}]}$: sum of $10$.

In the second test case, it can be shown that no array $a$ with all $|a_i| \leq m = 10^9$ satisfies all constraints.

Buggy Code:
#include<bits/stdc++.h>
// #include"debug.cpp"
#define int long long
using namespace std;
const int N = 2e5 + 10, MOD = 998244353, inf = 1e18;
int cases = 0;
void solve()
{
    int n, m; cin >> n >> m;
    string s; cin >> s;
    s = "#" + s;
    vector<int> b(n + 1);
    for (int i = 1; i <= n; i++) cin >> b[i];
    int ans = 0;
    for (int suff = 0; suff <= n; suff++)
    {
        bool good = true;
        for (int i = 1; i <= suff; i++)
        {
            if (s[i] == 'P')
            {
                good = false;
                break;
            }
        }
        for (int pref = suff + 1; pref <= n; pref++)
        {
            if (s[pref] == 'S')
            {
                good = false;
                break;
            }
        }
        if (!good) continue;
        int tot = -1;
        if (suff != 0) tot = b[1];
        if (suff + 1 <= n && tot != -1)
        {
            if (tot != b[n])
            {
                good = false;
                continue;
            }
        }
        for (int i = 1; i < suff; i++)
        {
            if (abs(b[i] - b[i + 1]) > m)
            {
                good = false;
                break;
            }
        }

        for (int pref = suff + 2; pref <= n; pref++)
        {
            if (abs(b[pref] - b[pref - 1]) > m)
            {
                good = false;
                break;
            }
            if (pref == n) tot = b[n];
        }
        if (abs(tot) > m * n) continue;
        if (suff != 0 && suff != n)
        {
            int sum = b[suff] + b[suff + 1] - tot;
            if (2 * m < abs(sum))
            {
                good = false;
            }
        }
        if (suff == 0)
        {
            if (abs(b[1]) > m) good = false;
        }
        if (suff == n)
        {
            if (abs(b[n]) > m) good = false;
        }
        if (good) ans++;
    }
    for (int lst = 1; lst < n; lst++)
    {
        if (s[lst] == 'S' || s[lst + 1] == 'P') continue;
        bool good = true;
        int tot = b[lst] + b[lst + 1];
        if (abs(tot) > m * n) continue;
        if (lst + 1 == n && (abs(b[lst + 1]) > m)) continue;
        if (lst == 1 && (abs(b[lst]) > m)) continue;
        vector<array<int, 2>> dp(n + 1);
        dp[1][0] = (s[1] != 'S') && (abs(b[1]) <= m);
        dp[1][1] = (s[1] != 'P') && (b[1] == tot);
        for (int i = 2; i <= lst; i++)
        {
            if (s[i] != 'S')
            {
                if (abs(b[i] - b[i - 1]) <= m) dp[i][0] = (dp[i][0] + dp[i - 1][0]) % MOD;
                int sum = b[i] + b[i - 1] - tot;
                int lrg = max(abs(sum / 2), abs(sum - sum / 2));
                if (lrg <= m)
                {
                    dp[i][0] = (dp[i][0] + dp[i - 1][1]) % MOD;
                }
            }
            if (s[i] != 'P')
            {
                if (b[i] + b[i - 1] == tot)
                {
                    dp[i][1] = (dp[i][1] + dp[i - 1][0]) % MOD;
                }
                if (abs(b[i - 1] - b[i]) <= m) dp[i][1] = (dp[i][1] + dp[i - 1][1]) % MOD;
            }
        }
        int lftans = dp[lst][0], inds = lst + 1;
        for (int i = lst + 2; i <= n; i++)
        {
            if (abs(b[i] - b[i - 1]) > m || (s[i] == 'P')) break;
            if (i == n && (abs(b[i]) > m)) break;
            inds = i;
        }
        int indp = n + 1;
        for (int i = n; i >= lst + 2; i--)
        {
            if (s[i] == 'S') break;
            if (i == n && tot != b[n]) break;
            if (i < n && abs(b[i] - b[i + 1]) > m) break;
            indp = i;
        }
        int rghans = 0;
        for (int i = lst + 1; i <= inds; i++)
        {
            if (indp <= i + 1) rghans++;
        }
        // cout << lftans << " " << inds << " " << indp << " " << rghans << '\n';
        int add = lftans * rghans % MOD;
        ans = (ans + add) % MOD;
    }
    cout << ans << '\n';
}
main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t; cin >> t;
    while (t--) solve();
}

**Instructions:**
- Focus on edge cases or scenarios that maximize the failure probability in faulty solutions.
- Due to the output length limit, you should generate a **small-scale** test input that is **complete and valid**.
- Output the test input directly, not code to generate it.

**Output format:**
```plaintext
{test input}
```

Think step by step.

Response:
```plaintext
3
4 10
PSPP
1 9 8 10
4 1000000000
????
1 1 1 4000000000
8 1000000000
?P?SSP?P
-857095623 -1424391899 -851974476 673437144 471253851 -543483033 364945701 -178537332
```


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Reconstruction
time_limit_ms: 2000
memory_limit_mb: 256
Description: There is a hidden array $a_1, a_2, \ldots, a_n$ of length $n$ whose elements are integers between $-m$ and $m$, inclusive.

You are given an array $b_1, b_2, \ldots, b_n$ of length $n$ and a string $s$ of length $n$ consisting of the characters $\texttt{P}$, $\texttt{S}$, and $\texttt{?}$.

For each $i$ from $1$ to $n$ inclusive, we must have:

  * If $s_i = \texttt{P}$, $b_i$ is the sum of $a_1$ through $a_i$.    * If $s_i = \texttt{S}$, $b_i$ is the sum of $a_i$ through $a_n$.

Output the number of ways to replace all $\texttt{?}$ in $s$ with either $\texttt{P}$ or $\texttt{S}$ such that there exists an array $a_1, a_2, \ldots, a_n$ with elements not exceeding $m$ by absolute value satisfying the constraints given by the array $b_1, b_2, \ldots, b_n$ and the string $s$.

Since the answer may be large, output it modulo $998\,244\,353$.

Input: The first line contains a single integer $t$ ($1 \leq t \leq 10^3$) — the number of test cases.

The first line of each test case contains two integers $n$ and $m$ ($2 \leq n \leq 2 \cdot 10^3$, $2 \leq m \leq 10^{9}$) — the length of the hidden array $a_1, a_2, \ldots, a_n$ and the maximum absolute value of an element $a_i$.

The second line of each test case contains a string $s$ of length $n$ consisting of characters $\texttt{P}$, $\texttt{S}$, and $\texttt{?}$.

The third line of each test case contains $n$ integers $b_1, b_2, \ldots, b_n$ ($|b_i| \leq m \cdot n$).

The sum of $n$ over all test cases does not exceed $5 \cdot 10^3$.

Output: For each test case, output a single integer — the number of ways to replace all $\texttt{?}$ in $s$ with either $\texttt{P}$ or $\texttt{S}$ that result in the existence of a valid array $a_1, a_2, \ldots, a_n$, modulo $998\,244\,353$.

Examples:
input:
6
4 10
PSPP
1 9 8 10
4 1000000000
????
1 1 1 4000000000
8 1000000000
?P?SSP?P
-857095623 -1424391899 -851974476 673437144 471253851 -543483033 364945701 -178537332
4 7
PPSS
4 2 1 3
9 20
?????????
1 2 3 4 5 6 7 8 9
3 1000000000
P??
-145463248 -974068460 -1287458396
output:
1
0
2
1
14
1

Note: In the first test case, we can see that the following array satisfies all constraints, thus the answer is $1$:

  1. $\texttt{P}$ — ${[\color{red}{\textbf{1}},3,4,2]}$: sum of $1$.    2. $\texttt{S}$ — ${[1,\color{red}{\textbf{3},4,2}]}$: sum of $9$.    3. $\texttt{P}$ — ${[\color{red}{1,3,\textbf{4}},2]}$: sum of $8$.    4. $\texttt{P}$ — ${[\color{red}{1,3,4,\textbf{2}}]}$: sum of $10$.

In the second test case, it can be shown that no array $a$ with all $|a_i| \leq m = 10^9$ satisfies all constraints.

Buggy Code:
import sys
input = sys.stdin.readline
MOD = 998244353
for _ in range(int(input())):
    n,m=map(int,input().split())
    s = input()
    b = list(map(int,input().split()))
    last = 0
    SOL = 0
    for i in range(n):
        if abs(b[i]) < (n-i) * m and (s[i] == "S" or s[i] == "?"):
            tot = last + b[i]
            if abs(tot) <= m * n:
                right = b[i]
                opt = 1
                dp = {(b[i],1):1}
                for j in range(i+1,n):
                    T = dict()
                    for tr in dp:
                        a,t = tr
                        val = dp[(a,t)]
                        if t == 0:
                            left = tot - a
                            dif = b[j] - left
                            right = tot - b[j]
                            if s[j] != "S" and abs(dif) <= m and abs(right) <= (n-j - 1) * m:
                                if (right,0) not in T: T[(right,0)] = 0
                                T[(right,0)] += val
                                T[(right,0)] %= MOD
                            if a == b[j] and s[j] != "P":
                                if (a,1) not in T: T[(a,1)] = 0
                                T[(a,1)] += val
                                T[(a,1)] %= MOD
                        else:
                            dif = b[j] - a
                            if abs(dif) <= m and abs(b[j]) <= (n-j) * m and s[j] != "P":
                                if (b[j],1) not in T: T[(b[j],1)] = 0
                                T[(b[j],1)] += val
                                T[(b[j],1)] %= MOD
                            xx = b[j] + a - b[j]
                            rem = tot - b[j]
                            if abs(xx) <= 2*m and s[j] != "S" and abs(rem) <= (n-j-1) * m:
                                if (rem,0) not in T: T[(rem,0)] = 0
                                T[(rem,0)] += val
                                T[(rem,0)] %= MOD
                    dp = T
                for x in dp.values():
                    SOL += x
                    SOL %= MOD
        if s[i] == "S": break
        if abs(b[i] - last) > m: break
        last = b[i]
    else:
        SOL += 1
        SOL %= MOD
    print(SOL)

**Instructions:**
- Focus on edge cases or scenarios that maximize the failure probability in faulty solutions.
- Due to the output length limit, you should generate a **small-scale** test input that is **complete and valid**.
- Output the test input directly, not code to generate it.

**Output format:**
```plaintext
{test input}
```

Think step by step.

Response:
```plaintext
1
4 2
????
4 2 2 4
```


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Reconstruction
time_limit_ms: 2000
memory_limit_mb: 256
Description: There is a hidden array $a_1, a_2, \ldots, a_n$ of length $n$ whose elements are integers between $-m$ and $m$, inclusive.

You are given an array $b_1, b_2, \ldots, b_n$ of length $n$ and a string $s$ of length $n$ consisting of the characters $\texttt{P}$, $\texttt{S}$, and $\texttt{?}$.

For each $i$ from $1$ to $n$ inclusive, we must have:

  * If $s_i = \texttt{P}$, $b_i$ is the sum of $a_1$ through $a_i$.    * If $s_i = \texttt{S}$, $b_i$ is the sum of $a_i$ through $a_n$.

Output the number of ways to replace all $\texttt{?}$ in $s$ with either $\texttt{P}$ or $\texttt{S}$ such that there exists an array $a_1, a_2, \ldots, a_n$ with elements not exceeding $m$ by absolute value satisfying the constraints given by the array $b_1, b_2, \ldots, b_n$ and the string $s$.

Since the answer may be large, output it modulo $998\,244\,353$.

Input: The first line contains a single integer $t$ ($1 \leq t \leq 10^3$) — the number of test cases.

The first line of each test case contains two integers $n$ and $m$ ($2 \leq n \leq 2 \cdot 10^3$, $2 \leq m \leq 10^{9}$) — the length of the hidden array $a_1, a_2, \ldots, a_n$ and the maximum absolute value of an element $a_i$.

The second line of each test case contains a string $s$ of length $n$ consisting of characters $\texttt{P}$, $\texttt{S}$, and $\texttt{?}$.

The third line of each test case contains $n$ integers $b_1, b_2, \ldots, b_n$ ($|b_i| \leq m \cdot n$).

The sum of $n$ over all test cases does not exceed $5 \cdot 10^3$.

Output: For each test case, output a single integer — the number of ways to replace all $\texttt{?}$ in $s$ with either $\texttt{P}$ or $\texttt{S}$ that result in the existence of a valid array $a_1, a_2, \ldots, a_n$, modulo $998\,244\,353$.

Examples:
input:
6
4 10
PSPP
1 9 8 10
4 1000000000
????
1 1 1 4000000000
8 1000000000
?P?SSP?P
-857095623 -1424391899 -851974476 673437144 471253851 -543483033 364945701 -178537332
4 7
PPSS
4 2 1 3
9 20
?????????
1 2 3 4 5 6 7 8 9
3 1000000000
P??
-145463248 -974068460 -1287458396
output:
1
0
2
1
14
1

Note: In the first test case, we can see that the following array satisfies all constraints, thus the answer is $1$:

  1. $\texttt{P}$ — ${[\color{red}{\textbf{1}},3,4,2]}$: sum of $1$.    2. $\texttt{S}$ — ${[1,\color{red}{\textbf{3},4,2}]}$: sum of $9$.    3. $\texttt{P}$ — ${[\color{red}{1,3,\textbf{4}},2]}$: sum of $8$.    4. $\texttt{P}$ — ${[\color{red}{1,3,4,\textbf{2}}]}$: sum of $10$.

In the second test case, it can be shown that no array $a$ with all $|a_i| \leq m = 10^9$ satisfies all constraints.

Buggy Code:
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include <bits/stdc++.h>
#define int long long
#define double long double
#define x first
#define y second
#define pb push_back
using namespace std;
using pii=pair <int,int>;
using tii=pair <pii,int>;
const int mod=998244353LL;
void solve(){
    int n,m;
    cin>>n>>m;
    char s[n+2];
    for (int i=1; i<=n; i++) cin>>s[i];
    int b[n+2];
    for (int i=1; i<=n; i++) cin>>b[i];
    s[0]='P'; b[0]=0; s[n+1]='S'; b[n+1]=0;
    int ans=0,dp[n+2][2];
    set <int> done;
    for (int gt=0; gt<=n; gt++){
        int sum=b[gt]+b[gt+1];
        if (done.find(sum)!=done.end()) continue;
        done.insert(sum);
        for (int i=0; i<n+2; i++){
            for (int j=0; j<2; j++) dp[i][j]=0;
        }
        dp[0][0]=1;
        for (int i=0; i<=n; i++){
            if (s[i+1]!='S'){
                if (abs(b[i+1]-b[i])<=m){
                    dp[i+1][0]+=dp[i][0];
                    dp[i+1][0]%=mod;
                }
                if (abs(b[i+1]+b[i])<=2*m){
                    dp[i+1][0]+=dp[i][1];
                    dp[i+1][0]%=mod;
                }
            }
            if (s[i+1]!='P'){
                if (b[i]+b[i+1]==sum){
                    dp[i+1][1]+=dp[i][0];
                    dp[i+1][1]%=mod;
                }
                if (abs(b[i+1]-b[i])<=m){
                    dp[i+1][1]+=dp[i][1];
                    dp[i+1][1]%=mod;
                }
            }
        }
        ans+=dp[n+1][1];
        ans%=mod;
    }
    cout<<ans<<'\n';
}
signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int t=1;
    cin>>t;
    while (t--) solve();
}

**Instructions:**
- Focus on edge cases or scenarios that maximize the failure probability in faulty solutions.
- Due to the output length limit, you should generate a **small-scale** test input that is **complete and valid**.
- Output the test input directly, not code to generate it.

**Output format:**
```plaintext
{test input}
```

Think step by step.

Response:
```plaintext
1
5 10
P?P?P
1 2 3 4 5
```


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Reconstruction
time_limit_ms: 2000
memory_limit_mb: 256
Description: There is a hidden array $a_1, a_2, \ldots, a_n$ of length $n$ whose elements are integers between $-m$ and $m$, inclusive.

You are given an array $b_1, b_2, \ldots, b_n$ of length $n$ and a string $s$ of length $n$ consisting of the characters $\texttt{P}$, $\texttt{S}$, and $\texttt{?}$.

For each $i$ from $1$ to $n$ inclusive, we must have:

  * If $s_i = \texttt{P}$, $b_i$ is the sum of $a_1$ through $a_i$.    * If $s_i = \texttt{S}$, $b_i$ is the sum of $a_i$ through $a_n$.

Output the number of ways to replace all $\texttt{?}$ in $s$ with either $\texttt{P}$ or $\texttt{S}$ such that there exists an array $a_1, a_2, \ldots, a_n$ with elements not exceeding $m$ by absolute value satisfying the constraints given by the array $b_1, b_2, \ldots, b_n$ and the string $s$.

Since the answer may be large, output it modulo $998\,244\,353$.

Input: The first line contains a single integer $t$ ($1 \leq t \leq 10^3$) — the number of test cases.

The first line of each test case contains two integers $n$ and $m$ ($2 \leq n \leq 2 \cdot 10^3$, $2 \leq m \leq 10^{9}$) — the length of the hidden array $a_1, a_2, \ldots, a_n$ and the maximum absolute value of an element $a_i$.

The second line of each test case contains a string $s$ of length $n$ consisting of characters $\texttt{P}$, $\texttt{S}$, and $\texttt{?}$.

The third line of each test case contains $n$ integers $b_1, b_2, \ldots, b_n$ ($|b_i| \leq m \cdot n$).

The sum of $n$ over all test cases does not exceed $5 \cdot 10^3$.

Output: For each test case, output a single integer — the number of ways to replace all $\texttt{?}$ in $s$ with either $\texttt{P}$ or $\texttt{S}$ that result in the existence of a valid array $a_1, a_2, \ldots, a_n$, modulo $998\,244\,353$.

Examples:
input:
6
4 10
PSPP
1 9 8 10
4 1000000000
????
1 1 1 4000000000
8 1000000000
?P?SSP?P
-857095623 -1424391899 -851974476 673437144 471253851 -543483033 364945701 -178537332
4 7
PPSS
4 2 1 3
9 20
?????????
1 2 3 4 5 6 7 8 9
3 1000000000
P??
-145463248 -974068460 -1287458396
output:
1
0
2
1
14
1

Note: In the first test case, we can see that the following array satisfies all constraints, thus the answer is $1$:

  1. $\texttt{P}$ — ${[\color{red}{\textbf{1}},3,4,2]}$: sum of $1$.    2. $\texttt{S}$ — ${[1,\color{red}{\textbf{3},4,2}]}$: sum of $9$.    3. $\texttt{P}$ — ${[\color{red}{1,3,\textbf{4}},2]}$: sum of $8$.    4. $\texttt{P}$ — ${[\color{red}{1,3,4,\textbf{2}}]}$: sum of $10$.

In the second test case, it can be shown that no array $a$ with all $|a_i| \leq m = 10^9$ satisfies all constraints.

Buggy Code:
#include "bits/stdc++.h"
using namespace std;

#ifdef Nero
#include "Deb.h"
#else
#define debug(...)
#endif

const int N = 2003;
const int md = 998244353;

int n, m;
char c[N];
int dp[N][2];
long long sum;
long long b[N];

void add(int& x, int y) {
  x += y;
  if (x >= md) x -= md;
}

int bt(int i, int last) {
  if (i == n + 2) {
    return 1;
  }
  int& ret = dp[i][last];
  if (ret != -1) {
    return ret;
  }
  ret = 0;
  if (c[i] == 'P') {
    if (last == 0 && llabs(b[i] - b[i - 1]) <= m) {
      add(ret, bt(i + 1, 0));
    }
    if (last == 1 && (b[i] + b[i - 1] - sum + 1) / 2 <= m) {
      add(ret, bt(i + 1, 0));
    }
  } else if (c[i] == 'S') {
    if (last == 0 && b[i] + b[i - 1] == sum) {
      add(ret, bt(i + 1, 1));
    }
    if (last == 1 && llabs(b[i] - b[i - 1]) <= m) {
      add(ret, bt(i + 1, 1));
    }
  } else {
    if (last == 0) {
      if (llabs(b[i] - b[i - 1]) <= m) {
        add(ret, bt(i + 1, 0));
      }
      if (b[i] + b[i - 1] == sum) {
        add(ret, bt(i + 1, 1));
      }
    } else {
      if ((b[i] + b[i - 1] - sum + 1) / 2 <= m) {
        add(ret, bt(i + 1, 0));
      }
      if (llabs(b[i] - b[i - 1]) <= m) {
        add(ret, bt(i + 1, 1));
      }
    }
  }
  return ret;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int tt;
  cin >> tt;
  while (tt--) {
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
      cin >> c[i];
    }
    for (int i = 1; i <= n; ++i) {
      cin >> b[i];
    }
    b[0] = b[n + 1] = 0;
    c[0] = 'P', c[n + 1] = 'S';
    int ans = 0;
    set<long long> sums;
    for (int i = 0; i <= n; ++i) {
      sum = b[i + 1] + b[i];
      if (sums.count(sum)) continue;
      sums.insert(sum);
      memset(dp, -1, sizeof dp);
      add(ans, bt(1, 0));
    }
    cout << ans << '\n';
  }
  return 0;
}

**Instructions:**
- Focus on edge cases or scenarios that maximize the failure probability in faulty solutions.
- Due to the output length limit, you should generate a **small-scale** test input that is **complete and valid**.
- Output the test input directly, not code to generate it.

**Output format:**
```plaintext
{test input}
```

Think step by step.

Response:
```plaintext
1
3 2
P?S
1 3 4
```


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Reconstruction
time_limit_ms: 2000
memory_limit_mb: 256
Description: There is a hidden array $a_1, a_2, \ldots, a_n$ of length $n$ whose elements are integers between $-m$ and $m$, inclusive.

You are given an array $b_1, b_2, \ldots, b_n$ of length $n$ and a string $s$ of length $n$ consisting of the characters $\texttt{P}$, $\texttt{S}$, and $\texttt{?}$.

For each $i$ from $1$ to $n$ inclusive, we must have:

  * If $s_i = \texttt{P}$, $b_i$ is the sum of $a_1$ through $a_i$.    * If $s_i = \texttt{S}$, $b_i$ is the sum of $a_i$ through $a_n$.

Output the number of ways to replace all $\texttt{?}$ in $s$ with either $\texttt{P}$ or $\texttt{S}$ such that there exists an array $a_1, a_2, \ldots, a_n$ with elements not exceeding $m$ by absolute value satisfying the constraints given by the array $b_1, b_2, \ldots, b_n$ and the string $s$.

Since the answer may be large, output it modulo $998\,244\,353$.

Input: The first line contains a single integer $t$ ($1 \leq t \leq 10^3$) — the number of test cases.

The first line of each test case contains two integers $n$ and $m$ ($2 \leq n \leq 2 \cdot 10^3$, $2 \leq m \leq 10^{9}$) — the length of the hidden array $a_1, a_2, \ldots, a_n$ and the maximum absolute value of an element $a_i$.

The second line of each test case contains a string $s$ of length $n$ consisting of characters $\texttt{P}$, $\texttt{S}$, and $\texttt{?}$.

The third line of each test case contains $n$ integers $b_1, b_2, \ldots, b_n$ ($|b_i| \leq m \cdot n$).

The sum of $n$ over all test cases does not exceed $5 \cdot 10^3$.

Output: For each test case, output a single integer — the number of ways to replace all $\texttt{?}$ in $s$ with either $\texttt{P}$ or $\texttt{S}$ that result in the existence of a valid array $a_1, a_2, \ldots, a_n$, modulo $998\,244\,353$.

Examples:
input:
6
4 10
PSPP
1 9 8 10
4 1000000000
????
1 1 1 4000000000
8 1000000000
?P?SSP?P
-857095623 -1424391899 -851974476 673437144 471253851 -543483033 364945701 -178537332
4 7
PPSS
4 2 1 3
9 20
?????????
1 2 3 4 5 6 7 8 9
3 1000000000
P??
-145463248 -974068460 -1287458396
output:
1
0
2
1
14
1

Note: In the first test case, we can see that the following array satisfies all constraints, thus the answer is $1$:

  1. $\texttt{P}$ — ${[\color{red}{\textbf{1}},3,4,2]}$: sum of $1$.    2. $\texttt{S}$ — ${[1,\color{red}{\textbf{3},4,2}]}$: sum of $9$.    3. $\texttt{P}$ — ${[\color{red}{1,3,\textbf{4}},2]}$: sum of $8$.    4. $\texttt{P}$ — ${[\color{red}{1,3,4,\textbf{2}}]}$: sum of $10$.

In the second test case, it can be shown that no array $a$ with all $|a_i| \leq m = 10^9$ satisfies all constraints.

Buggy Code:
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <set>
using namespace std;

#define ll long long
const int maxn = 2e3 + 5;
const int mod = 998244353;

#if false
#include <fstream>
#define cin in
#define cout out
ifstream in("src\\input.txt");
ofstream out("src\\output1.txt");
#endif

int n, m;
ll d[maxn], dd[maxn][2];
ll ans;
string s;

void test(int sidx, string s) {
	//s[sidx0] = 'P', s[sidx] = 'S'
	ll sum;
	if (sidx == 0) sum = d[0];
	else sum = d[sidx - 1] + d[sidx];

	for (int i = 0; i <= n; i++) dd[i][0] = dd[i][1] = 0;
	if (s[0] != 'S') dd[0][0] = d[0] <= m;
	if (s[0] != 'P' && sidx==0) dd[0][1] = 1;
/**
1
5 10
?S?SS
0 0 0 3 0
*/
	for (int j = 1; j <= n; j++) {
		if (s[j] != 'S') {
			//PP
			if (abs(d[j] - d[j - 1]) <= m) {
				dd[j][0] = (dd[j][0] + dd[j - 1][0]) % mod;
			}
			//SP
			if (abs(d[j] + d[j - 1] - sum) <= 2 * m) {
				dd[j][0] = (dd[j][0] + dd[j - 1][1]) % mod;
			}
		}
		if (s[j] != 'P') {
			//PS
			if (j >= sidx && d[j] + d[j - 1] == sum) {
				dd[j][1] = (dd[j][1] + dd[j - 1][0]) % mod;
			}
			//SS
			if (abs(d[j] - d[j - 1]) <= m) {
				dd[j][1] = (dd[j][1] + dd[j - 1][1]) % mod;
			}
		}
	}
	//cout << sidx << "----";
	//for (int i = 0; i <= n; i++) {
	//	cout << "(" << dd[i][0] << " " << dd[i][1] << ") ";
	//}
	//cout << endl;

	ans = (dd[n][1] + ans) % mod;
}
void solve() {
	cin >> n >> m;
	cin >> s;
	s = s + "S"; d[n] = 0;
	ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> d[i];
	}

	string t = s;
	t[0] = 'S';
	if (s[0] != 'P') test(0, t);
	for (int i = 1; i <= n; i++) {
		if (s[i - 1] != 'S' && s[i] != 'P') {
			// s[i0] = 'P', s[i] = 'S'
			string t = s;
			t[i - 1] = 'P', t[i] = 'S';
			test(i, t);
		}
	}
	cout << ans << endl;

}

int main() {
	int T;
	cin >> T;
	while (T--) {
		solve();
	}

}

**Instructions:**
- Focus on edge cases or scenarios that maximize the failure probability in faulty solutions.
- Due to the output length limit, you should generate a **small-scale** test input that is **complete and valid**.
- Output the test input directly, not code to generate it.

**Output format:**
```plaintext
{test input}
```

Think step by step.

Response:
```plaintext
1
5 10
?S?SS
0 0 0 3 0
```


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Reconstruction
time_limit_ms: 2000
memory_limit_mb: 256
Description: There is a hidden array $a_1, a_2, \ldots, a_n$ of length $n$ whose elements are integers between $-m$ and $m$, inclusive.

You are given an array $b_1, b_2, \ldots, b_n$ of length $n$ and a string $s$ of length $n$ consisting of the characters $\texttt{P}$, $\texttt{S}$, and $\texttt{?}$.

For each $i$ from $1$ to $n$ inclusive, we must have:

  * If $s_i = \texttt{P}$, $b_i$ is the sum of $a_1$ through $a_i$.    * If $s_i = \texttt{S}$, $b_i$ is the sum of $a_i$ through $a_n$.

Output the number of ways to replace all $\texttt{?}$ in $s$ with either $\texttt{P}$ or $\texttt{S}$ such that there exists an array $a_1, a_2, \ldots, a_n$ with elements not exceeding $m$ by absolute value satisfying the constraints given by the array $b_1, b_2, \ldots, b_n$ and the string $s$.

Since the answer may be large, output it modulo $998\,244\,353$.

Input: The first line contains a single integer $t$ ($1 \leq t \leq 10^3$) — the number of test cases.

The first line of each test case contains two integers $n$ and $m$ ($2 \leq n \leq 2 \cdot 10^3$, $2 \leq m \leq 10^{9}$) — the length of the hidden array $a_1, a_2, \ldots, a_n$ and the maximum absolute value of an element $a_i$.

The second line of each test case contains a string $s$ of length $n$ consisting of characters $\texttt{P}$, $\texttt{S}$, and $\texttt{?}$.

The third line of each test case contains $n$ integers $b_1, b_2, \ldots, b_n$ ($|b_i| \leq m \cdot n$).

The sum of $n$ over all test cases does not exceed $5 \cdot 10^3$.

Output: For each test case, output a single integer — the number of ways to replace all $\texttt{?}$ in $s$ with either $\texttt{P}$ or $\texttt{S}$ that result in the existence of a valid array $a_1, a_2, \ldots, a_n$, modulo $998\,244\,353$.

Examples:
input:
6
4 10
PSPP
1 9 8 10
4 1000000000
????
1 1 1 4000000000
8 1000000000
?P?SSP?P
-857095623 -1424391899 -851974476 673437144 471253851 -543483033 364945701 -178537332
4 7
PPSS
4 2 1 3
9 20
?????????
1 2 3 4 5 6 7 8 9
3 1000000000
P??
-145463248 -974068460 -1287458396
output:
1
0
2
1
14
1

Note: In the first test case, we can see that the following array satisfies all constraints, thus the answer is $1$:

  1. $\texttt{P}$ — ${[\color{red}{\textbf{1}},3,4,2]}$: sum of $1$.    2. $\texttt{S}$ — ${[1,\color{red}{\textbf{3},4,2}]}$: sum of $9$.    3. $\texttt{P}$ — ${[\color{red}{1,3,\textbf{4}},2]}$: sum of $8$.    4. $\texttt{P}$ — ${[\color{red}{1,3,4,\textbf{2}}]}$: sum of $10$.

In the second test case, it can be shown that no array $a$ with all $|a_i| \leq m = 10^9$ satisfies all constraints.

Buggy Code:
// LUOGU_RID: 163673479
#include <iostream>
using namespace std;
using ll= long long;
const int N=2e3+5,mod=998244353;
int n,f[N][2]; char s[N]; ll m,b[N];
ll _abs(ll x){ return x<0?-x:x; }
void solve(){ int ans=1;
	scanf("%d%lld%s",&n,&m,s+1);
	for(int i=1;i<=n;i++)
		scanf("%lld",b+i),
		ans&=(_abs(b[i]-b[i-1])<=m&&s[i]!='S');
	for(int i=1;i<=n;i++){
		if(s[i]!='P'){
			int sum=b[i-1]+b[i];
			f[i][1]=1,f[i][0]=0;
			for(int j=i+1;j<=n;j++){ f[j][0]=f[j][1]=0;
				if(s[j]!='P'){
					if(_abs(b[j]-b[j-1])<=m)
						f[j][1]=(f[j][1]+f[j-1][1])%mod;
					if(b[j-1]+b[j]==sum)
						f[j][1]=(f[j][1]+f[j-1][0])%mod;
				}
				if(s[j]!='S'){
					if(_abs(b[j]-b[j-1])<=m)
						f[j][0]=(f[j][0]+f[j-1][0])%mod;
					if(_abs(sum-b[j]-b[j-1])<=2*m)
						f[j][0]=(f[j][0]+f[j-1][1])%mod;
				}
			}
			if(_abs(b[n])>m) f[n][1]=0;
			if(b[n]^sum) f[n][0]=0;
			(ans+=(f[n][0]+f[n][1])%mod)%=mod;
		}
		if(_abs(b[i]-b[i-1])>m||s[i]=='S') break;
	} printf("%d\n",ans);
}
int main(){
	int T; scanf("%d",&T);
	while(T--) solve();
	return 0;
}

**Instructions:**
- Focus on edge cases or scenarios that maximize the failure probability in faulty solutions.
- Due to the output length limit, you should generate a **small-scale** test input that is **complete and valid**.
- Output the test input directly, not code to generate it.

**Output format:**
```plaintext
{test input}
```

Think step by step.

Response:
```plaintext
1
4 10
P?S?
1 2 3 4
```

### Explanation:
- **Test Case:**
  - **n = 4** (length of the hidden array)
  - **m = 10** (maximum absolute value of elements in the array)
  - **s = "P?S?"** (string with '?' characters to be replaced)
  - **b = [1, 2, 3, 4]** (array of sums)

### Why This Test Case?
1. **Edge Case with '?' Characters:**
   - The string `s` contains two '?' characters, which need to be replaced with either 'P' or 'S'. This tests the algorithm's ability to handle multiple unknowns and correctly count the number of valid replacements.

2. **Constraints:**
   - The values in `b` are small and increasing, which should make it easier to find valid arrays `a`. However, the '?' characters introduce uncertainty that the algorithm needs to handle correctly.

3. **Valid Array Example:**
   - One possible valid array `a` is `[1, 1, 1, 1]`:
     - `P` at position 1: `b[1] = 1` (sum of `a[1]` to `a[1]` is 1)
     - `?` at position 2: If replaced with `P`, `b[2] = 2` (sum of `a[1]` to `a[2]` is 2)
     - `S` at position 3: `b[3] = 3` (sum of `a[3]` to `a[4]` is 2 + 1 = 3)
     - `?` at position 4: If replaced with `S`, `b[4] = 4` (sum of `a[4]` to `a[4]` is 1)

4. **Expected Output:**
   - The correct output should be `2` because there are two valid ways to replace the '?' characters:
     - `s = "PSSP"`: `[1, 1, 1, 1]`
     - `s = "PSSS"`: `[1, 1, 1, 1]`

This test case is designed to expose issues in the buggy code by focusing on the handling of '?' characters and the constraints on the sums.


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Reconstruction
time_limit_ms: 2000
memory_limit_mb: 256
Description: There is a hidden array $a_1, a_2, \ldots, a_n$ of length $n$ whose elements are integers between $-m$ and $m$, inclusive.

You are given an array $b_1, b_2, \ldots, b_n$ of length $n$ and a string $s$ of length $n$ consisting of the characters $\texttt{P}$, $\texttt{S}$, and $\texttt{?}$.

For each $i$ from $1$ to $n$ inclusive, we must have:

  * If $s_i = \texttt{P}$, $b_i$ is the sum of $a_1$ through $a_i$.    * If $s_i = \texttt{S}$, $b_i$ is the sum of $a_i$ through $a_n$.

Output the number of ways to replace all $\texttt{?}$ in $s$ with either $\texttt{P}$ or $\texttt{S}$ such that there exists an array $a_1, a_2, \ldots, a_n$ with elements not exceeding $m$ by absolute value satisfying the constraints given by the array $b_1, b_2, \ldots, b_n$ and the string $s$.

Since the answer may be large, output it modulo $998\,244\,353$.

Input: The first line contains a single integer $t$ ($1 \leq t \leq 10^3$) — the number of test cases.

The first line of each test case contains two integers $n$ and $m$ ($2 \leq n \leq 2 \cdot 10^3$, $2 \leq m \leq 10^{9}$) — the length of the hidden array $a_1, a_2, \ldots, a_n$ and the maximum absolute value of an element $a_i$.

The second line of each test case contains a string $s$ of length $n$ consisting of characters $\texttt{P}$, $\texttt{S}$, and $\texttt{?}$.

The third line of each test case contains $n$ integers $b_1, b_2, \ldots, b_n$ ($|b_i| \leq m \cdot n$).

The sum of $n$ over all test cases does not exceed $5 \cdot 10^3$.

Output: For each test case, output a single integer — the number of ways to replace all $\texttt{?}$ in $s$ with either $\texttt{P}$ or $\texttt{S}$ that result in the existence of a valid array $a_1, a_2, \ldots, a_n$, modulo $998\,244\,353$.

Examples:
input:
6
4 10
PSPP
1 9 8 10
4 1000000000
????
1 1 1 4000000000
8 1000000000
?P?SSP?P
-857095623 -1424391899 -851974476 673437144 471253851 -543483033 364945701 -178537332
4 7
PPSS
4 2 1 3
9 20
?????????
1 2 3 4 5 6 7 8 9
3 1000000000
P??
-145463248 -974068460 -1287458396
output:
1
0
2
1
14
1

Note: In the first test case, we can see that the following array satisfies all constraints, thus the answer is $1$:

  1. $\texttt{P}$ — ${[\color{red}{\textbf{1}},3,4,2]}$: sum of $1$.    2. $\texttt{S}$ — ${[1,\color{red}{\textbf{3},4,2}]}$: sum of $9$.    3. $\texttt{P}$ — ${[\color{red}{1,3,\textbf{4}},2]}$: sum of $8$.    4. $\texttt{P}$ — ${[\color{red}{1,3,4,\textbf{2}}]}$: sum of $10$.

In the second test case, it can be shown that no array $a$ with all $|a_i| \leq m = 10^9$ satisfies all constraints.

Buggy Code:
#include <bits/stdc++.h>
using namespace std;
#define _rep(i_,a_,b_) for(int i_ = (a_); i_ <= (b_); ++i_)
#define mid ((L+R) >> 1)
#define multiCase() int testCnt = in(); _rep(curCase,1,testCnt)
#ifdef ONLINE_JUDGE
#define debug(...) 0
#else
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#endif
using ll = long long;
using pii = pair<int,int>;

int in(void) { int x; scanf("%d", &x); return x; } ll inl(void) { ll x; scanf("%lld", &x); return x; }
void out(int x) { printf("%d ", x); } void outln(int x) { printf("%d\n", x); }
void out(ll x) { printf("%lld ", x); } void outln(ll x) { printf("%lld\n", x); }
template<typename T> void chkmax(T &a, const T &b) { a = max(a, b); }
template<typename T> void chkmin(T &a, const T &b) { a = min(a, b); }
const int p = 998244353;
char s[2050]; ll a[2050];
int f[2050][2];
int main() {
	multiCase() {
		int n = in(), m = in();
		scanf("%s", s + 1);
		_rep(i,1,n) a[i] = inl();
		a[0] = a[n + 1] = 0;
		set<ll> psum;
		_rep(i,1,n + 1) psum.insert(a[i] + a[i - 1]);
		int ans = 0;
		for(auto &v : psum) {
			debug("v = %lld\n", v);
			f[0][0] = 1, f[0][1] = 0;
			_rep(i,1,n) {
				f[i][0] = f[i][1] = 0;
				// i as a prefix
				if(1ll * -m * i <= a[i] && a[i] <= 1ll * m * i && s[i] != 'S') {
					if(i != n) {
						if(-m <= a[i] - a[i - 1] && a[i] - a[i - 1] <= m) f[i][0] = f[i - 1][0];
						f[i][0] = (f[i][0] + f[i - 1][1]) % p;
					}
					else if(a[i] == v) {
						f[i][0] = f[i - 1][1];
						if(-m <= a[i] - a[i - 1] && a[i] - a[i - 1] <= m) f[i][0] = (f[i][0] + f[i - 1][0]);
						// f[i][0] = (f[i - 1][0] + f[i - 1][1]) % p;
					}
				}
				//i as a suffix
				if(1ll * -m * (n - i + 1) <= a[i] && a[i] <= 1ll * m * (n - i + 1) && s[i] != 'P') {
					if(i == 1 && a[i] != v) continue;
					if(-m <= a[i - 1] - a[i] && a[i - 1] - a[i] <= m) f[i][1] = f[i - 1][1];
					if(a[i] + a[i - 1] == v) f[i][1] = (f[i][1] + f[i - 1][0]) % p;
				}
				debug("%d %d\n", f[i][0], f[i][1]);
			}
			ans = (ans + f[n][0]) % p;
			ans = (ans + f[n][1]) % p;
		}
		outln(ans);
	}
	return 0;
}

**Instructions:**
- Focus on edge cases or scenarios that maximize the failure probability in faulty solutions.
- Due to the output length limit, you should generate a **small-scale** test input that is **complete and valid**.
- Output the test input directly, not code to generate it.

**Output format:**
```plaintext
{test input}
```

Think step by step.

Response:
```plaintext
1
3 10
P?S
1 10 10
```


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Reconstruction
time_limit_ms: 2000
memory_limit_mb: 256
Description: There is a hidden array $a_1, a_2, \ldots, a_n$ of length $n$ whose elements are integers between $-m$ and $m$, inclusive.

You are given an array $b_1, b_2, \ldots, b_n$ of length $n$ and a string $s$ of length $n$ consisting of the characters $\texttt{P}$, $\texttt{S}$, and $\texttt{?}$.

For each $i$ from $1$ to $n$ inclusive, we must have:

  * If $s_i = \texttt{P}$, $b_i$ is the sum of $a_1$ through $a_i$.    * If $s_i = \texttt{S}$, $b_i$ is the sum of $a_i$ through $a_n$.

Output the number of ways to replace all $\texttt{?}$ in $s$ with either $\texttt{P}$ or $\texttt{S}$ such that there exists an array $a_1, a_2, \ldots, a_n$ with elements not exceeding $m$ by absolute value satisfying the constraints given by the array $b_1, b_2, \ldots, b_n$ and the string $s$.

Since the answer may be large, output it modulo $998\,244\,353$.

Input: The first line contains a single integer $t$ ($1 \leq t \leq 10^3$) — the number of test cases.

The first line of each test case contains two integers $n$ and $m$ ($2 \leq n \leq 2 \cdot 10^3$, $2 \leq m \leq 10^{9}$) — the length of the hidden array $a_1, a_2, \ldots, a_n$ and the maximum absolute value of an element $a_i$.

The second line of each test case contains a string $s$ of length $n$ consisting of characters $\texttt{P}$, $\texttt{S}$, and $\texttt{?}$.

The third line of each test case contains $n$ integers $b_1, b_2, \ldots, b_n$ ($|b_i| \leq m \cdot n$).

The sum of $n$ over all test cases does not exceed $5 \cdot 10^3$.

Output: For each test case, output a single integer — the number of ways to replace all $\texttt{?}$ in $s$ with either $\texttt{P}$ or $\texttt{S}$ that result in the existence of a valid array $a_1, a_2, \ldots, a_n$, modulo $998\,244\,353$.

Examples:
input:
6
4 10
PSPP
1 9 8 10
4 1000000000
????
1 1 1 4000000000
8 1000000000
?P?SSP?P
-857095623 -1424391899 -851974476 673437144 471253851 -543483033 364945701 -178537332
4 7
PPSS
4 2 1 3
9 20
?????????
1 2 3 4 5 6 7 8 9
3 1000000000
P??
-145463248 -974068460 -1287458396
output:
1
0
2
1
14
1

Note: In the first test case, we can see that the following array satisfies all constraints, thus the answer is $1$:

  1. $\texttt{P}$ — ${[\color{red}{\textbf{1}},3,4,2]}$: sum of $1$.    2. $\texttt{S}$ — ${[1,\color{red}{\textbf{3},4,2}]}$: sum of $9$.    3. $\texttt{P}$ — ${[\color{red}{1,3,\textbf{4}},2]}$: sum of $8$.    4. $\texttt{P}$ — ${[\color{red}{1,3,4,\textbf{2}}]}$: sum of $10$.

In the second test case, it can be shown that no array $a$ with all $|a_i| \leq m = 10^9$ satisfies all constraints.

Buggy Code:
#include<bits/stdc++.h>
using namespace std;
const long long maxn=2000+10,mod=998244353;
long long all[maxn],dp[maxn],n,m,fake[maxn];
string s;

void solve(){
	dp[n+1]=1;
	for(long long i=n;i>=1;i--){
		long long ted=0,unnow=0,f=0,jam=all[i]+all[i-1];
		dp[i]=0;
		if(s[i-1]=='P'||(i!=1&&s[i-2]=='S')){
			continue;
		}
		for(long long j=i+1;j<=n;j++){
			if(f&&s[j-1]=='S'){
				break;
			}
			if(abs(all[j]-all[j-1])>m){
				ted=0;
			}
			if(s[j-1]!='S'&&f==0){
				if(unnow+all[j]+all[j-1]-jam+all[i-1]==all[j]){
					ted++;
				}
			}
			if(s[j-1]=='S'){
				ted=0;
			}
			if(s[j-1]!='S'&&all[j+1]+all[j]==jam){
				dp[i]+=ted*dp[j+1]%mod;
				dp[i]%=mod;
			}
			if(s[j-1]=='P'){
				f=1;
			}
			if(abs(all[j-1]-all[j])>m){
				if(s[j-1]=='S'){
					f=1;
					break;
				}
				f=1;
			}
			if(s[j-1]!='P'){
				unnow+=all[j-1]-all[j];
			}
			dp[i]%=mod;
		}
		if(f==0&&abs(all[n])<=m){
			dp[i]++;
		}
	}
	long long mainres=0;
	for(long long i=1;i<=n;i++){
		if(s[i-1]=='S'){
			break;
		}
		if(abs(all[i]-all[i-1])>m){
			break;
		}
		mainres+=dp[i+1];
		mainres%=mod;
	}
	mainres+=dp[1];
	mainres%=mod;
	cout<<mainres<<"\n";
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	long long t;
	cin>>t;
	for(long long asd=0;asd<t;asd++){
		cin>>n>>m;
		cin>>s;
		for(long long i=1;i<=n;i++){
			cin>>all[i];
		}
		solve();
		for(long long i=0;i<=n+4;i++){
			dp[i]=0;
		}
	}
}

**Instructions:**
- Focus on edge cases or scenarios that maximize the failure probability in faulty solutions.
- Due to the output length limit, you should generate a **small-scale** test input that is **complete and valid**.
- Output the test input directly, not code to generate it.

**Output format:**
```plaintext
{test input}
```

Think step by step.

Response:
```plaintext
1
4 10
P?S?
1 10 10 1
```

**Explanation:**
This test case is designed to expose potential issues in the buggy code by using a small but tricky input. Here’s the breakdown:

1. **Input Size**: The test case is small, with \( n = 4 \) and \( m = 10 \), which is within the constraints and manageable for testing.
2. **String Configuration**: The string `P?S?` contains two `?` characters, which need to be replaced with either `P` or `S`. This will test the algorithm's ability to handle multiple unknowns.
3. **Array `b`**: The array `b` is `[1, 10, 10, 1]`. This configuration is designed to:
   - Ensure that the first element `P` is valid.
   - The second element `?` can be either `P` or `S` but must be consistent with the remaining elements.
   - The third element `S` is valid.
   - The fourth element `?` can be either `P` or `S` but must be consistent with the previous elements.

**Expected Behavior:**
- The algorithm should correctly handle the `?` characters and determine the number of valid ways to replace them.
- The correct output for this test case should be `2`, as there are two valid ways to replace the `?` characters:
  1. `PSSP`
  2. `PSPS`

This test case is designed to expose issues in the logic of the buggy code, particularly in how it handles the unknowns and the constraints given by the `b` array.


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Reconstruction
time_limit_ms: 2000
memory_limit_mb: 256
Description: There is a hidden array $a_1, a_2, \ldots, a_n$ of length $n$ whose elements are integers between $-m$ and $m$, inclusive.

You are given an array $b_1, b_2, \ldots, b_n$ of length $n$ and a string $s$ of length $n$ consisting of the characters $\texttt{P}$, $\texttt{S}$, and $\texttt{?}$.

For each $i$ from $1$ to $n$ inclusive, we must have:

  * If $s_i = \texttt{P}$, $b_i$ is the sum of $a_1$ through $a_i$.    * If $s_i = \texttt{S}$, $b_i$ is the sum of $a_i$ through $a_n$.

Output the number of ways to replace all $\texttt{?}$ in $s$ with either $\texttt{P}$ or $\texttt{S}$ such that there exists an array $a_1, a_2, \ldots, a_n$ with elements not exceeding $m$ by absolute value satisfying the constraints given by the array $b_1, b_2, \ldots, b_n$ and the string $s$.

Since the answer may be large, output it modulo $998\,244\,353$.

Input: The first line contains a single integer $t$ ($1 \leq t \leq 10^3$) — the number of test cases.

The first line of each test case contains two integers $n$ and $m$ ($2 \leq n \leq 2 \cdot 10^3$, $2 \leq m \leq 10^{9}$) — the length of the hidden array $a_1, a_2, \ldots, a_n$ and the maximum absolute value of an element $a_i$.

The second line of each test case contains a string $s$ of length $n$ consisting of characters $\texttt{P}$, $\texttt{S}$, and $\texttt{?}$.

The third line of each test case contains $n$ integers $b_1, b_2, \ldots, b_n$ ($|b_i| \leq m \cdot n$).

The sum of $n$ over all test cases does not exceed $5 \cdot 10^3$.

Output: For each test case, output a single integer — the number of ways to replace all $\texttt{?}$ in $s$ with either $\texttt{P}$ or $\texttt{S}$ that result in the existence of a valid array $a_1, a_2, \ldots, a_n$, modulo $998\,244\,353$.

Examples:
input:
6
4 10
PSPP
1 9 8 10
4 1000000000
????
1 1 1 4000000000
8 1000000000
?P?SSP?P
-857095623 -1424391899 -851974476 673437144 471253851 -543483033 364945701 -178537332
4 7
PPSS
4 2 1 3
9 20
?????????
1 2 3 4 5 6 7 8 9
3 1000000000
P??
-145463248 -974068460 -1287458396
output:
1
0
2
1
14
1

Note: In the first test case, we can see that the following array satisfies all constraints, thus the answer is $1$:

  1. $\texttt{P}$ — ${[\color{red}{\textbf{1}},3,4,2]}$: sum of $1$.    2. $\texttt{S}$ — ${[1,\color{red}{\textbf{3},4,2}]}$: sum of $9$.    3. $\texttt{P}$ — ${[\color{red}{1,3,\textbf{4}},2]}$: sum of $8$.    4. $\texttt{P}$ — ${[\color{red}{1,3,4,\textbf{2}}]}$: sum of $10$.

In the second test case, it can be shown that no array $a$ with all $|a_i| \leq m = 10^9$ satisfies all constraints.

Buggy Code:
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vi = vector<int>;
using pi = pair<int, int>;

const int mod = 998244353;
const int inf = 1e9;
const ll oo = 1e18;

void solve() {
	int n, m; cin >> n >> m;
	string s = "P", t; cin >> t;
	s += t + 'S';
	vector<ll> a(n + 2, 0), b(n + 2, 0);
	for (int i = 1; i <= n; i++) cin >> a[i];
	vector<ll> dps(n + 1, 0);
	vector<map<ll, ll>> dpp(n + 1);
	dps[0] = (s[1] != 'P');
	dpp[0][oo] = (s[1] != 'S' && llabs(a[1]) <= m);
	for (int i = 1; i <= n; i++) {
		ll val = a[i] + a[i + 1];
		if (s[i] == 'S') continue;
		if (s[i + 1] != 'P') {
			dps[i] = (dpp[i - 1].count(val) ? dpp[i - 1][val] : 0) + (dpp[i - 1].count(oo) ? dpp[i - 1][oo] : 0);
			if (llabs(a[i + 1] - a[i - 1]) <= 2 * m) {
    			for (int j = i - 2; j >= 0; j--) {
    				if (s[j + 1] == 'P') break;
    				if (a[j] + a[j + 1] != a[i] + a[i + 1]) continue;
    				if (j + 2 < i && llabs(a[j + 1] - a[j + 2]) > m) break;
    				(dps[i] += dps[j]) %= mod;
    			}
            }

		}
		if (s[i + 1] != 'S') {
			if (llabs(a[i] - a[i + 1]) > m) continue;
			for (auto [u, v] : dpp[i - 1]) dpp[i][u] = v;
			if (s[i - 1] == 'P') continue;
			if (llabs(a[i] - a[i - 2]) <= 2 * m) (dpp[i][a[i - 2] + a[i - 1]] += dps[i - 2]) %= mod;
			for (int j = i - 3; j >= 0; j--) {
				if (s[j + 1] == 'P') break;
				if (llabs(a[i] - a[j] - (a[j + 1] - a[i - 1])) > 2 * m) continue;
				if (llabs(a[j + 1] - a[j + 2]) > m) break;
				(dpp[i][a[j] + a[j + 1]] += dps[j]) %= mod;
			}
		}
	}
	ll ans = 0;
	for (int i = n; i >= 0; i--) {
		if (s[i + 1] == 'P') break;
		(ans += dps[i]) %= mod;
		if (llabs(a[i + 1] - a[i]) > m) break;
	}
	cout << ans << endl;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
#endif
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	int T = 1;
	cin >> T;
	while (T --) solve();
	return 0;
}

**Instructions:**
- Focus on edge cases or scenarios that maximize the failure probability in faulty solutions.
- Due to the output length limit, you should generate a **small-scale** test input that is **complete and valid**.
- Output the test input directly, not code to generate it.

**Output format:**
```plaintext
{test input}
```

Think step by step.

Response:
```plaintext
1
4 10
P?PS
1 9 8 10
```


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Reconstruction
time_limit_ms: 2000
memory_limit_mb: 256
Description: There is a hidden array $a_1, a_2, \ldots, a_n$ of length $n$ whose elements are integers between $-m$ and $m$, inclusive.

You are given an array $b_1, b_2, \ldots, b_n$ of length $n$ and a string $s$ of length $n$ consisting of the characters $\texttt{P}$, $\texttt{S}$, and $\texttt{?}$.

For each $i$ from $1$ to $n$ inclusive, we must have:

  * If $s_i = \texttt{P}$, $b_i$ is the sum of $a_1$ through $a_i$.    * If $s_i = \texttt{S}$, $b_i$ is the sum of $a_i$ through $a_n$.

Output the number of ways to replace all $\texttt{?}$ in $s$ with either $\texttt{P}$ or $\texttt{S}$ such that there exists an array $a_1, a_2, \ldots, a_n$ with elements not exceeding $m$ by absolute value satisfying the constraints given by the array $b_1, b_2, \ldots, b_n$ and the string $s$.

Since the answer may be large, output it modulo $998\,244\,353$.

Input: The first line contains a single integer $t$ ($1 \leq t \leq 10^3$) — the number of test cases.

The first line of each test case contains two integers $n$ and $m$ ($2 \leq n \leq 2 \cdot 10^3$, $2 \leq m \leq 10^{9}$) — the length of the hidden array $a_1, a_2, \ldots, a_n$ and the maximum absolute value of an element $a_i$.

The second line of each test case contains a string $s$ of length $n$ consisting of characters $\texttt{P}$, $\texttt{S}$, and $\texttt{?}$.

The third line of each test case contains $n$ integers $b_1, b_2, \ldots, b_n$ ($|b_i| \leq m \cdot n$).

The sum of $n$ over all test cases does not exceed $5 \cdot 10^3$.

Output: For each test case, output a single integer — the number of ways to replace all $\texttt{?}$ in $s$ with either $\texttt{P}$ or $\texttt{S}$ that result in the existence of a valid array $a_1, a_2, \ldots, a_n$, modulo $998\,244\,353$.

Examples:
input:
6
4 10
PSPP
1 9 8 10
4 1000000000
????
1 1 1 4000000000
8 1000000000
?P?SSP?P
-857095623 -1424391899 -851974476 673437144 471253851 -543483033 364945701 -178537332
4 7
PPSS
4 2 1 3
9 20
?????????
1 2 3 4 5 6 7 8 9
3 1000000000
P??
-145463248 -974068460 -1287458396
output:
1
0
2
1
14
1

Note: In the first test case, we can see that the following array satisfies all constraints, thus the answer is $1$:

  1. $\texttt{P}$ — ${[\color{red}{\textbf{1}},3,4,2]}$: sum of $1$.    2. $\texttt{S}$ — ${[1,\color{red}{\textbf{3},4,2}]}$: sum of $9$.    3. $\texttt{P}$ — ${[\color{red}{1,3,\textbf{4}},2]}$: sum of $8$.    4. $\texttt{P}$ — ${[\color{red}{1,3,4,\textbf{2}}]}$: sum of $10$.

In the second test case, it can be shown that no array $a$ with all $|a_i| \leq m = 10^9$ satisfies all constraints.

Buggy Code:
// im so close :pleading: im bussing
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define int ll

#define endl '\n'
#define pb push_back
using pi = array<int, 2>;

const int MOD = 998244353;

const int P = 0, S = 1;

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int T;
  cin >> T;

  while (T--) {
    int n, m;
    string s;
    cin >> n >> m >> s;

    vector<int> a(n + 4);
    for (int i = 2; i <= n + 1; ++i) {
      cin >> a[i];
    }
    s = 'P' + s + 'S';
    n = s.size();
    s = '$' + s;

    int ptr = n - 1, last_sum = 0;
    while (s[ptr] == 'S') {
      last_sum += a[ptr] - a[ptr + 1];
      --ptr;
    }
    auto solve = [&](int sum) -> int {
      vector<vector<int>> dp(n + 1, vector<int>(2));
      dp[1][P] = 1;
      for (int i = 2; i <= n; ++i) {
        if (s[i] == 'P' || s[i] == '?') {
          if (abs(a[i] - a[i - 1]) <= m) {
            dp[i][P] = (dp[i][P] + dp[i - 1][P]) % MOD;
          }
          dp[i][P] = (dp[i][P] + dp[i - 1][S]) % MOD;
        }
        if (s[i] == 'S' || s[i] == '?') {
          if (abs(a[i - 1] - a[i]) <= m) {
            dp[i][S] = (dp[i][S] + dp[i - 1][S]) % MOD;
          }
          if (a[i] == sum - a[i - 1]) {
            dp[i][S] = (dp[i][S] + dp[i - 1][P]) % MOD;
          }
        }
      }

      return (dp[n][0] + dp[n][1]) % MOD;
    };

    int ans = 0;
    while (ptr > 0 && s[ptr] != 'P') {
      s[ptr] = 'P';
      ans = (ans + solve(last_sum + a[ptr])) % MOD;
      s[ptr] = 'S';
      last_sum += a[ptr] - a[ptr + 1];
      --ptr;
    }
    ans = (ans + solve(last_sum + a[ptr])) % MOD;

    cout << ans << endl;
  }
}

/*
pot sa fixez suma in O(n) si apoi sa verific in O(n) daca/cate solutii exista ca gen o sa fie determinate chestiile nj

P[i] determina S[i + 1]
S[i + 1] determina P[i]

S[i + 1] = sum - P[i]
*/

**Instructions:**
- Focus on edge cases or scenarios that maximize the failure probability in faulty solutions.
- Due to the output length limit, you should generate a **small-scale** test input that is **complete and valid**.
- Output the test input directly, not code to generate it.

**Output format:**
```plaintext
{test input}
```

Think step by step.

Response:
```plaintext
1
4 10
PP?S
4 2 1 3
```