**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Non-academic Problem
time_limit_ms: 2000
memory_limit_mb: 256
Description: You are given a connected undirected graph, the vertices of which are numbered with integers from $1$ to $n$. Your task is to minimize the number of pairs of vertices $1 \leq u < v \leq n$ between which there exists a path in this graph. To achieve this, you can remove exactly one edge from the graph.

Find the smallest number of pairs of vertices!

Input: Each test consists of several sets of input data. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$) — the number of sets of input data. Then follows their description.

The first line of each set of input data contains two integers $n$ and $m$ ($2 \leq n \leq 10^5$, $n - 1 \leq m \leq \min(10^5, \frac{n \cdot (n - 1)}{2})$) — the number of vertices in the graph and the number of edges.

Each of the next $m$ lines contains two integers $u$ and $v$ ($1 \leq u, v \leq n, u \neq v$), indicating that there is an undirected edge in the graph between vertices $u$ and $v$.

It is guaranteed that the given graph is connected and without multiple edges.

It is guaranteed that the sum of $n$ and the sum of $m$ over all sets of input data does not exceed $2 \cdot 10^5$.

Output: For each set of input data, output the smallest number of pairs of reachable vertices, if exactly one edge can be removed.

Examples:
input:
6
2 1
1 2
3 3
1 2
2 3
1 3
5 5
1 2
1 3
3 4
4 5
5 3
6 7
1 2
1 3
2 3
3 4
4 5
4 6
5 6
5 5
1 2
1 3
2 3
2 4
3 5
10 12
1 2
1 3
2 3
2 4
4 5
5 6
6 7
7 4
3 8
8 9
9 10
10 8
output:
0
3
4
6
6
21

Note: In the first set of input data, we will remove the single edge $(1, 2)$ and the only pair of vertices $(1, 2)$ will become unreachable from each other.

In the second set of input data, no matter which edge we remove, all vertices will be reachable from each other.

In the fourth set of input data, the graph looks like this initially.

![](CDN_BASE_URL/c00467697f2843fb1ecf4e292e93aa87)

We will remove the edge $(3, 4)$ and then the only reachable pairs of vertices will be $(1, 2)$, $(1, 3)$, $(2, 3)$, $(4, 5)$, $(4, 6)$, $(5, 6)$.

![](CDN_BASE_URL/9d2fd2df4094f1654c448ff596e16eb3)

In the sixth set of input data, the graph looks like this initially.

![](CDN_BASE_URL/a18a02e5685863de8060f83f96c068e2)

After removing the edge $(2, 4)$, the graph will look like this. Thus, there will be $21$ pairs of reachable vertices.

![](CDN_BASE_URL/f53901ac967e9f60a7423e8ea66c67e4)

Buggy Code:
import sys

input = sys.stdin.readline
sys.setrecursionlimit(200000)

def get_bcc(graph):
    n = len(graph)

    bcc = [-1] * n  # the component that node i belongs to
    comp = 1  # current component
    low_link = [-1] * n  # smallest time reachable of a node reachable from the DFS subtree of node i
    node_id = [-1] * n  # time at which node i was discovered
    time = 0
    path = []  # nodes currently in the dfs traversal
    in_path = [False] * n
    comp_sz = [0]

    def dfs(cur, prev):
        nonlocal time, comp
        node_id[cur] = low_link[cur] = time
        path.append(cur)
        in_path[cur] = True
        time += 1

        for adj in graph[cur]:
            if adj == prev:
                continue
            if node_id[adj] == -1:  # not yet visited
                dfs(adj, cur)
                low_link[cur] = min(low_link[cur], low_link[adj])

            else:  # back edge, since we arrived at a node on the current path
                low_link[cur] = min(low_link[cur], node_id[adj])

        if node_id[cur] == low_link[cur]:  # root in dfs tree, assign bcc values to everything in this bcc
            sz = 0
            while True:
                in_path[path[-1]] = False
                bcc[path[-1]] = comp
                sz += 1
                if path.pop() == cur:
                    break
            comp_sz.append(sz)
            comp += 1

    for i in range(1, n):
        if node_id[i] == -1:
            dfs(i, -1)
    return bcc, comp_sz

def solve():
    N, M = map(int, input().split())
    graph = [[] for _ in range(N + 1)]
    for _ in range(M):
        a, b = map(int, input().split())
        graph[a].append(b)
        graph[b].append(a)

    bcc, comp_sz = get_bcc(graph)  # compress BCCs into a single node
    tree = [set() for _ in range(max(bcc) + 1)]
    for i in range(1, len(graph)):
        for adj in graph[i]:
            if bcc[i] != bcc[adj]:
                tree[bcc[i]].add(bcc[adj])
    tree = list(map(list, tree))
    graph = tree
    N = len(graph)
    get_cost = lambda x: x * (x - 1) // 2

    sz = [-1] * (N + 1)  # sum of nodes in the subtree of cur (including cur)

    def precompute(cur, prev):
        total = comp_sz[cur]
        for adj in tree[cur]:
            if adj == prev:
                continue
            precompute(adj, cur)
            total += sz[adj]
        sz[cur] = total

    precompute(1, -1)
    # print(sz)
    best = float('inf')
    total = sz[1]
    for i in sz:
        if i == -1:
            continue
        best = min(best, get_cost(i) + get_cost(total - i))
    print(best)

t = int(input())
for _ in range(t):
    solve()

"""
1
5 5
1 2
1 3
3 4
4 5
5 3

1 3
2 3
3 1
3 2

"""

**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 edge cases and scenarios that are likely to cause issues. The buggy code uses a depth-first search (DFS) to find biconnected components (BCCs) and then calculates the minimum number of reachable pairs after removing one edge. Here are the steps to generate a suitable test input:

1. **Identify Potential Issues:**
   - The code might have issues with handling graphs that have multiple biconnected components.
   - The code might have issues with handling graphs where removing a specific edge can significantly change the number of reachable pairs.

2. **Choose a Small-Scale Test Input:**
   - We need a graph that is small enough to be manageable but complex enough to challenge the algorithm.
   - A good candidate is a graph with a few vertices and edges that can be split into multiple components by removing a single edge.

3. **Construct the Graph:**
   - Let's construct a graph with 4 vertices and 4 edges that forms a cycle.
   - Removing one edge from the cycle should split the graph into two components.

Here is the test input:

```plaintext
1
4 4
1 2
2 3
3 4
4 1
```

**Explanation:**
- The graph is a cycle with 4 vertices: 1, 2, 3, and 4.
- The edges are (1, 2), (2, 3), (3, 4), and (4, 1).
- Removing any one of these edges will split the graph into two components.
- For example, if we remove the edge (1, 2), the graph will be split into two components: {1, 4} and {2, 3}.
- The number of reachable pairs in each component is:
  - Component {1, 4}: 1 pair (1, 4)
  - Component {2, 3}: 1 pair (2, 3)
- The total number of reachable pairs is 2.

This test input should expose the bug in the given buggy code, as it requires the code to correctly handle the splitting of the graph and the calculation of reachable pairs.


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Non-academic Problem
time_limit_ms: 2000
memory_limit_mb: 256
Description: You are given a connected undirected graph, the vertices of which are numbered with integers from $1$ to $n$. Your task is to minimize the number of pairs of vertices $1 \leq u < v \leq n$ between which there exists a path in this graph. To achieve this, you can remove exactly one edge from the graph.

Find the smallest number of pairs of vertices!

Input: Each test consists of several sets of input data. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$) — the number of sets of input data. Then follows their description.

The first line of each set of input data contains two integers $n$ and $m$ ($2 \leq n \leq 10^5$, $n - 1 \leq m \leq \min(10^5, \frac{n \cdot (n - 1)}{2})$) — the number of vertices in the graph and the number of edges.

Each of the next $m$ lines contains two integers $u$ and $v$ ($1 \leq u, v \leq n, u \neq v$), indicating that there is an undirected edge in the graph between vertices $u$ and $v$.

It is guaranteed that the given graph is connected and without multiple edges.

It is guaranteed that the sum of $n$ and the sum of $m$ over all sets of input data does not exceed $2 \cdot 10^5$.

Output: For each set of input data, output the smallest number of pairs of reachable vertices, if exactly one edge can be removed.

Examples:
input:
6
2 1
1 2
3 3
1 2
2 3
1 3
5 5
1 2
1 3
3 4
4 5
5 3
6 7
1 2
1 3
2 3
3 4
4 5
4 6
5 6
5 5
1 2
1 3
2 3
2 4
3 5
10 12
1 2
1 3
2 3
2 4
4 5
5 6
6 7
7 4
3 8
8 9
9 10
10 8
output:
0
3
4
6
6
21

Note: In the first set of input data, we will remove the single edge $(1, 2)$ and the only pair of vertices $(1, 2)$ will become unreachable from each other.

In the second set of input data, no matter which edge we remove, all vertices will be reachable from each other.

In the fourth set of input data, the graph looks like this initially.

![](CDN_BASE_URL/c00467697f2843fb1ecf4e292e93aa87)

We will remove the edge $(3, 4)$ and then the only reachable pairs of vertices will be $(1, 2)$, $(1, 3)$, $(2, 3)$, $(4, 5)$, $(4, 6)$, $(5, 6)$.

![](CDN_BASE_URL/9d2fd2df4094f1654c448ff596e16eb3)

In the sixth set of input data, the graph looks like this initially.

![](CDN_BASE_URL/a18a02e5685863de8060f83f96c068e2)

After removing the edge $(2, 4)$, the graph will look like this. Thus, there will be $21$ pairs of reachable vertices.

![](CDN_BASE_URL/f53901ac967e9f60a7423e8ea66c67e4)

Buggy Code:
import sys
sys.setrecursionlimit(100000)

def func(nodes, n, root):
    visited = set()
    dp = {node: 10**9 for node in nodes}
    tree_size = {node: 0 for node in nodes}
    levels = {node: 0 for node in nodes}
    parents = {}

    def dfs(node, level):
        visited.add(node)
        levels[node] = level
        dp[node] = level
        tree_size[node] += 1
        for neighbor in nodes[node]:
            if neighbor not in visited:
                parents[neighbor] = node
                dfs(neighbor, level + 1)
                tree_size[node] += tree_size[neighbor]
            if node not in parents or parents[node] != neighbor:
                dp[node] = min(dp[node], dp[neighbor])
        return

    dfs(root, 0)
    # print('tree_size', tree_size)
    # print('levels', levels)
    # print('dp', dp)
    # print('parents', parents)
    res = n * (n - 1) // 2
    for v in parents:
        u = parents[v]
        if dp[v] > levels[u]:
            num = tree_size[v]
            num2 = n - num
            res = min(res, num * (num - 1) // 2 + num2 * (num2 - 1) // 2)
    return res

t = int(input())
for i in range(t):
    n, m = [int(el) for el in input().split(' ')]
    nodes = {}
    for j in range(m):
        a, b = [int(el) for el in input().split(' ')]
        nodes[a] = nodes.get(a, []) + [b]
        nodes[b] = nodes.get(b, []) + [a]
    res = func(nodes, n, a)
    print(res)

**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, let's consider the following aspects:

1. **Graph Structure**: The graph should be connected and have a structure that can potentially expose issues in the depth-first search (DFS) and the logic for calculating the minimum number of pairs of reachable vertices.

2. **Edge Cases**: The test input should include cases where the graph has a specific structure that might cause the DFS to behave incorrectly, such as cycles or specific tree structures.

3. **Small Scale**: The test input should be small enough to be manageable but large enough to test the algorithm thoroughly.

Given these considerations, let's create a test input that includes a graph with a cycle and a structure that might cause the DFS to miscalculate the minimum number of pairs of reachable vertices.

### Test Input

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

### Explanation

- **Graph Structure**: The graph is a cycle with an additional edge. Specifically, it forms a cycle with vertices 1, 2, 3, 4, and 5, and an additional edge between vertices 1 and 3.
- **Edge Cases**: The cycle and the additional edge create a structure that can test the DFS logic and the calculation of the minimum number of pairs of reachable vertices.
- **Small Scale**: The graph has 5 vertices and 6 edges, which is small enough to be manageable but large enough to test the algorithm thoroughly.

This test input should help expose any bugs in the given buggy code, particularly in how it handles cycles and the calculation of the minimum number of pairs of reachable vertices.


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Non-academic Problem
time_limit_ms: 2000
memory_limit_mb: 256
Description: You are given a connected undirected graph, the vertices of which are numbered with integers from $1$ to $n$. Your task is to minimize the number of pairs of vertices $1 \leq u < v \leq n$ between which there exists a path in this graph. To achieve this, you can remove exactly one edge from the graph.

Find the smallest number of pairs of vertices!

Input: Each test consists of several sets of input data. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$) — the number of sets of input data. Then follows their description.

The first line of each set of input data contains two integers $n$ and $m$ ($2 \leq n \leq 10^5$, $n - 1 \leq m \leq \min(10^5, \frac{n \cdot (n - 1)}{2})$) — the number of vertices in the graph and the number of edges.

Each of the next $m$ lines contains two integers $u$ and $v$ ($1 \leq u, v \leq n, u \neq v$), indicating that there is an undirected edge in the graph between vertices $u$ and $v$.

It is guaranteed that the given graph is connected and without multiple edges.

It is guaranteed that the sum of $n$ and the sum of $m$ over all sets of input data does not exceed $2 \cdot 10^5$.

Output: For each set of input data, output the smallest number of pairs of reachable vertices, if exactly one edge can be removed.

Examples:
input:
6
2 1
1 2
3 3
1 2
2 3
1 3
5 5
1 2
1 3
3 4
4 5
5 3
6 7
1 2
1 3
2 3
3 4
4 5
4 6
5 6
5 5
1 2
1 3
2 3
2 4
3 5
10 12
1 2
1 3
2 3
2 4
4 5
5 6
6 7
7 4
3 8
8 9
9 10
10 8
output:
0
3
4
6
6
21

Note: In the first set of input data, we will remove the single edge $(1, 2)$ and the only pair of vertices $(1, 2)$ will become unreachable from each other.

In the second set of input data, no matter which edge we remove, all vertices will be reachable from each other.

In the fourth set of input data, the graph looks like this initially.

![](CDN_BASE_URL/c00467697f2843fb1ecf4e292e93aa87)

We will remove the edge $(3, 4)$ and then the only reachable pairs of vertices will be $(1, 2)$, $(1, 3)$, $(2, 3)$, $(4, 5)$, $(4, 6)$, $(5, 6)$.

![](CDN_BASE_URL/9d2fd2df4094f1654c448ff596e16eb3)

In the sixth set of input data, the graph looks like this initially.

![](CDN_BASE_URL/a18a02e5685863de8060f83f96c068e2)

After removing the edge $(2, 4)$, the graph will look like this. Thus, there will be $21$ pairs of reachable vertices.

![](CDN_BASE_URL/f53901ac967e9f60a7423e8ea66c67e4)

Buggy Code:
import java.util.*;

public class MinimizeReachablePairs {

    static int n, m;
    static List<Integer>[] adj;
    static boolean[] visited;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();

        while (t-- > 0) {
            n = sc.nextInt();
            m = sc.nextInt();

            adj = new ArrayList[n + 1];
            for (int i = 1; i <= n; i++) {
                adj[i] = new ArrayList<>();
            }

            int[][] edges = new int[m][2];
            for (int i = 0; i < m; i++) {
                int u = sc.nextInt();
                int v = sc.nextInt();
                adj[u].add(v);
                adj[v].add(u);
                edges[i][0] = u;
                edges[i][1] = v;
            }

            // We need to find the minimum reachable pairs after removing one edge
            int minReachablePairs = Integer.MAX_VALUE;

            for (int[] edge : edges) {
                int u = edge[0];
                int v = edge[1];

                // Temporarily remove the edge
                adj[u].remove(Integer.valueOf(v));
                adj[v].remove(Integer.valueOf(u));

                // Find the sizes of the two components
                visited = new boolean[n + 1];
                int size1 = bfsSize(u);
                int size2 = bfsSize(v);

                // Calculate the number of reachable pairs
                int reachablePairs = (size1 * (size1 - 1)) / 2 + (size2 * (size2 - 1)) / 2;
                minReachablePairs = Math.min(minReachablePairs, reachablePairs);

                // Re-add the edge
                adj[u].add(v);
                adj[v].add(u);
            }

            System.out.println(minReachablePairs);
        }
        sc.close();
    }

    private static int bfsSize(int start) {
        Queue<Integer> queue = new LinkedList<>();
        queue.add(start);
        visited[start] = true;
        int size = 0;

        while (!queue.isEmpty()) {
            int node = queue.poll();
            size++;

            for (int neighbor : adj[node]) {
                if (!visited[neighbor]) {
                    visited[neighbor] = true;
                    queue.add(neighbor);
                }
            }
        }
        return size;
    }
}

**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, let's consider the following steps:

1. **Understand the Bug**: The buggy code temporarily removes an edge and then uses BFS to find the sizes of the two resulting components. However, it might fail to correctly handle cases where the removal of an edge does not actually disconnect the graph, or where the graph has a specific structure that makes the BFS results incorrect.

2. **Identify Edge Cases**:
   - **Tree Structure**: A tree (a connected graph with no cycles) where removing any edge will always disconnect the graph.
   - **Graph with Cycles**: A graph that has cycles, where removing an edge might not disconnect the graph.
   - **Graph with Multiple Edges Between the Same Vertices**: Although the problem guarantees no multiple edges, we should still consider graphs that are close to having such structures.
   - **Graph with High Connectivity**: A highly connected graph where removing any single edge does not significantly affect the number of reachable pairs.

3. **Construct a Test Case**:
   - A small graph with a cycle and a specific edge that, when removed, does not disconnect the graph but changes the number of reachable pairs in a non-obvious way.

Given these considerations, let's construct a test case:

```plaintext
1
4 5
1 2
2 3
3 4
4 1
1 3
```

**Explanation**:
- This graph has 4 vertices and 5 edges, forming a cycle with an additional edge.
- Removing the edge (1, 3) will not disconnect the graph, but it will change the number of reachable pairs.
- The initial graph has the following pairs of reachable vertices: (1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4).
- Removing the edge (1, 3) will reduce the number of reachable pairs to: (1, 2), (1, 4), (2, 3), (2, 4), (3, 4).

This test case should expose the bug in the code, as the BFS might not correctly account for the change in the number of reachable pairs when the edge (1, 3) is removed.


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Non-academic Problem
time_limit_ms: 2000
memory_limit_mb: 256
Description: You are given a connected undirected graph, the vertices of which are numbered with integers from $1$ to $n$. Your task is to minimize the number of pairs of vertices $1 \leq u < v \leq n$ between which there exists a path in this graph. To achieve this, you can remove exactly one edge from the graph.

Find the smallest number of pairs of vertices!

Input: Each test consists of several sets of input data. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$) — the number of sets of input data. Then follows their description.

The first line of each set of input data contains two integers $n$ and $m$ ($2 \leq n \leq 10^5$, $n - 1 \leq m \leq \min(10^5, \frac{n \cdot (n - 1)}{2})$) — the number of vertices in the graph and the number of edges.

Each of the next $m$ lines contains two integers $u$ and $v$ ($1 \leq u, v \leq n, u \neq v$), indicating that there is an undirected edge in the graph between vertices $u$ and $v$.

It is guaranteed that the given graph is connected and without multiple edges.

It is guaranteed that the sum of $n$ and the sum of $m$ over all sets of input data does not exceed $2 \cdot 10^5$.

Output: For each set of input data, output the smallest number of pairs of reachable vertices, if exactly one edge can be removed.

Examples:
input:
6
2 1
1 2
3 3
1 2
2 3
1 3
5 5
1 2
1 3
3 4
4 5
5 3
6 7
1 2
1 3
2 3
3 4
4 5
4 6
5 6
5 5
1 2
1 3
2 3
2 4
3 5
10 12
1 2
1 3
2 3
2 4
4 5
5 6
6 7
7 4
3 8
8 9
9 10
10 8
output:
0
3
4
6
6
21

Note: In the first set of input data, we will remove the single edge $(1, 2)$ and the only pair of vertices $(1, 2)$ will become unreachable from each other.

In the second set of input data, no matter which edge we remove, all vertices will be reachable from each other.

In the fourth set of input data, the graph looks like this initially.

![](CDN_BASE_URL/c00467697f2843fb1ecf4e292e93aa87)

We will remove the edge $(3, 4)$ and then the only reachable pairs of vertices will be $(1, 2)$, $(1, 3)$, $(2, 3)$, $(4, 5)$, $(4, 6)$, $(5, 6)$.

![](CDN_BASE_URL/9d2fd2df4094f1654c448ff596e16eb3)

In the sixth set of input data, the graph looks like this initially.

![](CDN_BASE_URL/a18a02e5685863de8060f83f96c068e2)

After removing the edge $(2, 4)$, the graph will look like this. Thus, there will be $21$ pairs of reachable vertices.

![](CDN_BASE_URL/f53901ac967e9f60a7423e8ea66c67e4)

Buggy Code:
import java.io.*;
import java.util.*;

public class QUES1 {
    static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    static BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
    static StringTokenizer st;

    static Scanner s = new Scanner(System.in);

    static int MOD = (int) (1e9 + 7);

    static List<List<Integer>> graph = new ArrayList<>();
    static boolean[] vis ;
    public static void solve() throws IOException {
        st = new StringTokenizer(reader.readLine());
        int n = Integer.parseInt(st.nextToken());
        int m = Integer.parseInt(st.nextToken());
        for (int i=0;i<=n;i++) graph.add(i,new ArrayList<>());
        for (int i=0;i<m;i++){
            st = new StringTokenizer(reader.readLine());
            int u = Integer.parseInt(st.nextToken());
            int v = Integer.parseInt(st.nextToken());
            graph.get(u).add(v);
            graph.get(v).add(u);
        }
//        System.out.println(graph);

        ans = ((long) (n) *(n-1))/2;
        c = 0;
        count = 0;
        int[] time = new int[n+1];
        int[] low = new int[n+1];
        vis = new boolean[n+1];
        bridges = new ArrayList<>();
        dfs(1,-1,time,low,n);

//        System.out.println(bridges);

        for (List<Integer> ls : bridges){
            count = 0 ;
            vis = new boolean[n+1];
            noOfNodes(ls.get(0),ls.get(1));
//            System.out.println(count + " " + ls);
            ans = Math.min(ans, (long) (count) *(count-1)/2 + (long) (n - count) *(n-count-1)/2);
        }

        writer.write(ans+"\n");

    }

    public static void noOfNodes(int i , int node){
        count++;
        vis[i] =true;
        for (Integer num : graph.get(i)){
            if (!vis[num] && num!=node) noOfNodes(num,node);
        }
    }

    static int c;
    static long ans;

    static int count ;

    static List<List<Integer>> bridges = new ArrayList<>();

    public static void dfs(int i , int par , int[] time , int[] low,int n){
        c++;
        time[i] = c;
        low[i] = c;
        vis[i] = true;
        for (Integer num : graph.get(i)){
            if (!vis[num]) {
                dfs(num,i,time,low,n);
                if (time[i]<low[num]){
                    bridges.add(new ArrayList<>(Arrays.asList(i,num)));
//                    System.out.println(count + " " + i + " " + num);

//                    ans = Math.min(ans, (long) (count) *(count-1)/2 + (long) (n - count) *(n-count-1)/2);
                }
                low[i] = Math.min(low[i],low[num]);
            }
            else if (num!=par){
                low[i] = Math.min(low[i],low[num]);
            }
        }
    }

    public static void main(String[] args) throws IOException {

        int t = Integer.parseInt(reader.readLine());
        // int t = 1;
        while (t-- > 0) {
            solve();
        }

        writer.flush();
        writer.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
3
3 3
1 2
2 3
1 3
4 4
1 2
2 3
3 4
4 1
5 6
1 2
2 3
3 4
4 5
1 3
3 5
```


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Dyn-scripted Robot (Hard Version)
time_limit_ms: 3000
memory_limit_mb: 256
Description: This is the hard version of the problem. The only difference is that in this version $k \le 10^{12}$. You can make hacks only if both versions of the problem are solved.

Given a $w \times h$ rectangle on the $Oxy$ plane, with points $(0, 0)$ at the bottom-left and $(w, h)$ at the top-right of the rectangle.

You also have a robot initially at point $(0, 0)$ and a script $s$ of $n$ characters. Each character is either L, R, U, or D, which tells the robot to move left, right, up, or down respectively.

The robot can only move inside the rectangle; otherwise, it will change the script $s$ as follows:

  * If it tries to move outside a vertical border, it changes all L characters to R's (and vice versa, all R's to L's).    * If it tries to move outside a horizontal border, it changes all U characters to D's (and vice versa, all D's to U's).

Then, it will execute the changed script starting from the character which it couldn't execute.

![](CDN_BASE_URL/ff5ae9758c965c2d8398c936e9581dab) An example of the robot's movement process, $s = \texttt{"ULULURD"}$

The script $s$ will be executed for $k$ times continuously. All changes to the string $s$ will be retained even when it is repeated. During this process, how many times will the robot move to the point $(0, 0)$ in total? Note that the initial position does NOT count.

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 four integers $n$, $k$, $w$, and $h$ ($1 \le n, w, h \le 10^6$; $1 \le k \le 10^{12}$).

The second line contains a single string $s$ of size $n$ ($s_i \in \\{\texttt{L}, \texttt{R}, \texttt{U}, \texttt{D}\\}$) — the script to be executed.

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^6$.

Output: For each test case, print a single integer — the number of times the robot reaches $(0, 0)$ when executing script $s$ for $k$ times continuously.

Examples:
input:
6
2 4 2 2
UR
4 2 1 1
LLDD
6 3 3 1
RLRRRL
5 6 3 3
RUURD
7 5 3 4
RRDLUUU
7 123456789999 3 2
ULULURD
output:
1
4
3
1
1
41152263332

Note: In the first test case, the robot only moves up and right for the first two executions. After that, it occupies the position $(2, 2)$. For the next two executions, it moves down and left and finishes at $(0, 0)$. So the answer is $1$.

In the second test case, each time executing the script the robot visits the origin twice. And since $k=2$, it visits the origin $2 \cdot 2 = 4$ times overall.

![](CDN_BASE_URL/ea799abf84f8a212d5a0d782be4d5e9c)

In the third test case, the visualization is shown as below:

![](CDN_BASE_URL/c6a5be14982b3d57a5103783598d4683)

Buggy Code:
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll exgcd(ll a,ll b,ll &x,ll &y) {
	if(!b) return x=1,y=0,a;
	ll g=exgcd(b,a%b,y,x);
	return y-=a/b*x,g;
}
ll inv(ll a,ll p) {
	ll x,y; exgcd(a,p,x,y);
	return (x%p+p)%p;
}
const int MAXN=1e6+5;
int px[MAXN],py[MAXN];
char str[MAXN];
void solve() {
	ll _,k,n,m,ans=0;
	cin>>_>>k>>m>>n>>(str+1),n*=2,m*=2;
	for(int i=1;i<=_;++i) {
		px[i]=(px[i-1]+(str[i]=='D'?n-1:str[i]=='U'))%n;
		py[i]=(py[i-1]+(str[i]=='L'?m-1:str[i]=='R'))%m;
	}
	ll dx=px[_],dy=py[_],gx=__gcd(dx,n),gy=__gcd(dy,m);
	ll p=n/gx,q=m/gy,ix=inv(dx/=gx,p),iy=inv(dy/=gy,q);
	ll u,v,d=exgcd(p,q,u,v),e=p/d*q;
	for(int i=1;i<=_;++i) {
		ll rx=(n-px[i])%n,ry=(m-py[i])%m;
		if(rx%gx||ry%gy) continue;
		rx=rx/gx*ix%p,ry=ry/gy*iy%q;
		//k mod p = rx, k mod q = ry
		if((ry-rx)%d) continue;
		ll z=q/d,s=((ry-rx)/d*u%z+z)%z,k0=s*p+rx;
		if(k0<=k) ans+=(k-k0-1)/e+1;
	}
	cout<<ans<<"\n";
}
signed main() {
	ios::sync_with_stdio(false);
	int T; 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
7 123456789999 3 2
ULULURD
```


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Dyn-scripted Robot (Hard Version)
time_limit_ms: 3000
memory_limit_mb: 256
Description: This is the hard version of the problem. The only difference is that in this version $k \le 10^{12}$. You can make hacks only if both versions of the problem are solved.

Given a $w \times h$ rectangle on the $Oxy$ plane, with points $(0, 0)$ at the bottom-left and $(w, h)$ at the top-right of the rectangle.

You also have a robot initially at point $(0, 0)$ and a script $s$ of $n$ characters. Each character is either L, R, U, or D, which tells the robot to move left, right, up, or down respectively.

The robot can only move inside the rectangle; otherwise, it will change the script $s$ as follows:

  * If it tries to move outside a vertical border, it changes all L characters to R's (and vice versa, all R's to L's).    * If it tries to move outside a horizontal border, it changes all U characters to D's (and vice versa, all D's to U's).

Then, it will execute the changed script starting from the character which it couldn't execute.

![](CDN_BASE_URL/ff5ae9758c965c2d8398c936e9581dab) An example of the robot's movement process, $s = \texttt{"ULULURD"}$

The script $s$ will be executed for $k$ times continuously. All changes to the string $s$ will be retained even when it is repeated. During this process, how many times will the robot move to the point $(0, 0)$ in total? Note that the initial position does NOT count.

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 four integers $n$, $k$, $w$, and $h$ ($1 \le n, w, h \le 10^6$; $1 \le k \le 10^{12}$).

The second line contains a single string $s$ of size $n$ ($s_i \in \\{\texttt{L}, \texttt{R}, \texttt{U}, \texttt{D}\\}$) — the script to be executed.

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^6$.

Output: For each test case, print a single integer — the number of times the robot reaches $(0, 0)$ when executing script $s$ for $k$ times continuously.

Examples:
input:
6
2 4 2 2
UR
4 2 1 1
LLDD
6 3 3 1
RLRRRL
5 6 3 3
RUURD
7 5 3 4
RRDLUUU
7 123456789999 3 2
ULULURD
output:
1
4
3
1
1
41152263332

Note: In the first test case, the robot only moves up and right for the first two executions. After that, it occupies the position $(2, 2)$. For the next two executions, it moves down and left and finishes at $(0, 0)$. So the answer is $1$.

In the second test case, each time executing the script the robot visits the origin twice. And since $k=2$, it visits the origin $2 \cdot 2 = 4$ times overall.

![](CDN_BASE_URL/ea799abf84f8a212d5a0d782be4d5e9c)

In the third test case, the visualization is shown as below:

![](CDN_BASE_URL/c6a5be14982b3d57a5103783598d4683)

Buggy Code:
// Problem: F2. Dyn-scripted Robot (Hard Version)
// Contest: Codeforces - Codeforces Round 963 (Div. 2)
// URL: https://codeforces.com/contest/1993/problem/F2
// Memory Limit: 256 MB
// Time Limit: 3000 ms
//
// Powered by CP Editor (https://cpeditor.org)

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

#define rep(n) for (int _i_i_ = (n); _i_i_; --_i_i_)
#define mem(arr, x) memset((arr), x, sizeof (arr))
#define mkp make_pair
#define edge(y, x, ver) for (int _i_ = h[x], y = ver[_i_]; _i_; y = ver[_i_ = nxt[_i_]])
#define rand_init mt19937 rnd(chrono::system_clock::now().time_since_epoch().count())
#define setdb(v) setprecision(v)
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int maxn = 1e6 + 5;

ll n, k, w, h;
string s;

ll exgcd(ll a, ll b, ll &x, ll &y) {
	if (b == 0) {
		x = 1, y = 0;
		return a;
	}
	ll g = exgcd(b, a % b, y, x);
	y -= a / b * x;
	return g;
}

ll get(ll b, ll c, ll m) { // a * b === c (mod m)
	ll x, y, g = exgcd(b, m, x, y);
	if (c % g != 0) return -1;
	x %= m;
	if (x < 0) x += m;
	return c / g * x % (m / g);
}

ll crt(ll b1, ll m1, ll b2, ll m2) {
	ll t = (b2 - b1) % m2;
	if (t < 0) t += m2;
	ll k = get(m1, t, m2);
	if (k == -1) return -1;
	return b1 + k * b2;
}

ll x[maxn], y[maxn];

void solve() {
	cin >> n >> k >> w >> h;
	cin >> s;
	for (int i = 1; i <= n; ++i) {
		x[i] = (x[i - 1] + (s[i - 1] == 'R') - (s[i - 1] == 'L') + 2 * w) % (2 * w);
		y[i] = (y[i - 1] + (s[i - 1] == 'U') - (s[i - 1] == 'D') + 2 * h) % (2 * h);
	}
	ll g1 = gcd(x[n], 2 * w), g2 = gcd(y[n], 2 * h);
	ll ww = 2 * w / g1, hh = 2 * h / g2, l = lcm(ww, hh);
	ll ans = 0;
	for (int i = 1; i <= n; ++i) {
		ll a1 = get(x[n], 2 * w - x[i], 2 * w), a2 = get(y[n], 2 * h - y[i], 2 * h);
		if (a1 == -1 || a2 == -1) continue;
		ll r = crt(a1, ww, a2, hh) % l;
		if (r == -1 || r >= k) continue;
		ans += (k - r - 1) / l + 1;
	}
	cout << ans << '\n';
}

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	int t = 1;
	cin >> t;
	rep (t) {
		solve();
	}
	return 0;
}

/*
+---------------------------------------------+
|grey|green|cyan|blue|purple|yellow|orange|red|
+---------------------------------------------+
*/

**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
7 123456789999 3 2
ULULURD
```


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Dyn-scripted Robot (Hard Version)
time_limit_ms: 3000
memory_limit_mb: 256
Description: This is the hard version of the problem. The only difference is that in this version $k \le 10^{12}$. You can make hacks only if both versions of the problem are solved.

Given a $w \times h$ rectangle on the $Oxy$ plane, with points $(0, 0)$ at the bottom-left and $(w, h)$ at the top-right of the rectangle.

You also have a robot initially at point $(0, 0)$ and a script $s$ of $n$ characters. Each character is either L, R, U, or D, which tells the robot to move left, right, up, or down respectively.

The robot can only move inside the rectangle; otherwise, it will change the script $s$ as follows:

  * If it tries to move outside a vertical border, it changes all L characters to R's (and vice versa, all R's to L's).    * If it tries to move outside a horizontal border, it changes all U characters to D's (and vice versa, all D's to U's).

Then, it will execute the changed script starting from the character which it couldn't execute.

![](CDN_BASE_URL/ff5ae9758c965c2d8398c936e9581dab) An example of the robot's movement process, $s = \texttt{"ULULURD"}$

The script $s$ will be executed for $k$ times continuously. All changes to the string $s$ will be retained even when it is repeated. During this process, how many times will the robot move to the point $(0, 0)$ in total? Note that the initial position does NOT count.

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 four integers $n$, $k$, $w$, and $h$ ($1 \le n, w, h \le 10^6$; $1 \le k \le 10^{12}$).

The second line contains a single string $s$ of size $n$ ($s_i \in \\{\texttt{L}, \texttt{R}, \texttt{U}, \texttt{D}\\}$) — the script to be executed.

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^6$.

Output: For each test case, print a single integer — the number of times the robot reaches $(0, 0)$ when executing script $s$ for $k$ times continuously.

Examples:
input:
6
2 4 2 2
UR
4 2 1 1
LLDD
6 3 3 1
RLRRRL
5 6 3 3
RUURD
7 5 3 4
RRDLUUU
7 123456789999 3 2
ULULURD
output:
1
4
3
1
1
41152263332

Note: In the first test case, the robot only moves up and right for the first two executions. After that, it occupies the position $(2, 2)$. For the next two executions, it moves down and left and finishes at $(0, 0)$. So the answer is $1$.

In the second test case, each time executing the script the robot visits the origin twice. And since $k=2$, it visits the origin $2 \cdot 2 = 4$ times overall.

![](CDN_BASE_URL/ea799abf84f8a212d5a0d782be4d5e9c)

In the third test case, the visualization is shown as below:

![](CDN_BASE_URL/c6a5be14982b3d57a5103783598d4683)

Buggy Code:
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define pir pair <ll, ll>
#define mkp make_pair
#define fi first
#define se second
#define pb push_back
using namespace std;
const ll maxn = 1e6 + 10;
ll t, n, k, w, h, a[maxn], b[maxn], ans;
char s[maxn];
void exgcd(ll a, ll b, ll &x, ll &y) {
	if(!b) { x = 1, y = 0; return; }
	exgcd(b, a % b, x, y);
	ll t = x; x = y;
	y = t - a / b * y;
}
ll calc(ll p1, ll q1, ll p2, ll q2) {
	if(!p1 && q1 || !p2 && q2) return 0;
	ll d1, m1, d2, m2, x, y, g;
	if(p1) {
		g = __gcd(p1, w << 1);
		if(q1 % g) return 0;
		exgcd(p1, w << 1, x, y);
		m1 = (w << 1) / g, d1 = (x % m1 + m1) % m1;
		d1 *= q1 / g;
	} else d1 = 0, m1 = 1;
	if(p2) {
		g = __gcd(p2, h << 1);
		if(q2 % g) return 0;
		exgcd(p2, h << 1, x, y);
		m2 = (h << 1) / g, d2 = (x % m2 + m2) % m2;
		d2 *= q2 / g;
	} else d2 = 0, m2 = 1;
	if((d1 - d2) % __gcd(m1, m2)) return 0;
	ll m = m1 * m2 / __gcd(m1, m2);
	ll t = (d1 - d2) / __gcd(m1, m2);
	exgcd(m1, m2, x, y);
	x *= t;
	ll res = d1 - x * m1; res = (res % m + m) % m;
	if(res >= k) return 0;
	return 1 + (k - res - 1) / m;
}
int main() {
	scanf("%lld", &t);
	while(t--) {
		scanf("%lld%lld%lld%lld%s", &n, &k, &w, &h, s + 1);
		for(ll i = 1, cx = 0, cy = 0; i <= n; i++) {
			switch(s[i]) {
				case 'L': ++cx; break;
				case 'R': --cx; break;
				case 'U': ++cy; break;
				case 'D': --cy; break;
			}
			cx = (cx + (w << 1)) % (w << 1);
			cy = (cy + (h << 1)) % (h << 1);
			a[i] = cx, b[i] = cy;
		} ans = 0;
		for(ll i = 1; i <= n; i++) {
			ll p = ((w << 1) - a[i]) % (w << 1),
			   q = ((h << 1) - b[i]) % (h << 1);
			ans += calc(a[n], p, b[n], q);
		} printf("%lld\n", 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
2 4 2 2
UR
```


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Dyn-scripted Robot (Hard Version)
time_limit_ms: 3000
memory_limit_mb: 256
Description: This is the hard version of the problem. The only difference is that in this version $k \le 10^{12}$. You can make hacks only if both versions of the problem are solved.

Given a $w \times h$ rectangle on the $Oxy$ plane, with points $(0, 0)$ at the bottom-left and $(w, h)$ at the top-right of the rectangle.

You also have a robot initially at point $(0, 0)$ and a script $s$ of $n$ characters. Each character is either L, R, U, or D, which tells the robot to move left, right, up, or down respectively.

The robot can only move inside the rectangle; otherwise, it will change the script $s$ as follows:

  * If it tries to move outside a vertical border, it changes all L characters to R's (and vice versa, all R's to L's).    * If it tries to move outside a horizontal border, it changes all U characters to D's (and vice versa, all D's to U's).

Then, it will execute the changed script starting from the character which it couldn't execute.

![](CDN_BASE_URL/ff5ae9758c965c2d8398c936e9581dab) An example of the robot's movement process, $s = \texttt{"ULULURD"}$

The script $s$ will be executed for $k$ times continuously. All changes to the string $s$ will be retained even when it is repeated. During this process, how many times will the robot move to the point $(0, 0)$ in total? Note that the initial position does NOT count.

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 four integers $n$, $k$, $w$, and $h$ ($1 \le n, w, h \le 10^6$; $1 \le k \le 10^{12}$).

The second line contains a single string $s$ of size $n$ ($s_i \in \\{\texttt{L}, \texttt{R}, \texttt{U}, \texttt{D}\\}$) — the script to be executed.

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^6$.

Output: For each test case, print a single integer — the number of times the robot reaches $(0, 0)$ when executing script $s$ for $k$ times continuously.

Examples:
input:
6
2 4 2 2
UR
4 2 1 1
LLDD
6 3 3 1
RLRRRL
5 6 3 3
RUURD
7 5 3 4
RRDLUUU
7 123456789999 3 2
ULULURD
output:
1
4
3
1
1
41152263332

Note: In the first test case, the robot only moves up and right for the first two executions. After that, it occupies the position $(2, 2)$. For the next two executions, it moves down and left and finishes at $(0, 0)$. So the answer is $1$.

In the second test case, each time executing the script the robot visits the origin twice. And since $k=2$, it visits the origin $2 \cdot 2 = 4$ times overall.

![](CDN_BASE_URL/ea799abf84f8a212d5a0d782be4d5e9c)

In the third test case, the visualization is shown as below:

![](CDN_BASE_URL/c6a5be14982b3d57a5103783598d4683)

Buggy Code:
from collections import defaultdict
import sys
input = sys.stdin.readline
MOD = 10**9 + 7

def read_array(factory):
    return [factory(num) for num in input().strip().split()]
def print_array(arr):
    print(" ".join(map(str, arr)))

from functools import reduce
def chinese_remainder(n, a):
    sum = 0
    prod = reduce(lambda a, b: a*b, n)
    for n_i, a_i in zip(n, a):
        p = prod // n_i
        sum += a_i * mul_inv(p, n_i) * p
    return sum % prod

def mul_inv(a, b):
    b0 = b
    x0, x1 = 0, 1
    if b == 1: return 1
    while a > 1:
        q = a // b
        a, b = b, a%b
        x0, x1 = x1 - q * x0, x0
    if x1 < 0: x1 += b0
    return x1

def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x % y)

def solve(k, w, h, s):
    x, y = 0, 0
    cnt = defaultdict(int)
    for char in s:
        if char == 'R':
            x += 1
        elif char == 'L':
            x -= 1
        elif char == 'U':
            y += 1
        elif char == 'D':
            y -= 1
        cnt[(x % (2*w), y % (2*h))] += 1

    # tot = 0
    # for i in range(k):
    #     tot += cnt[((-i*x) % (2*w), (-i*y) % (2*h))]

    tot = 0
    for (xj, yj), c in cnt.items():
        ## tot += number of 0 <= i < k such that
        ## xj = -i*x (mod 2*w) and yj = -i*y (mod 2*h)
        # tot += c * sum(1 for i in range(k) if xj == (-i*x) % (2*w) and yj == (-i*y) % (2*h))

        ## OR, EQUIVALENTLY
        ## -xj = i*x (mod 2*w) and yj = i*y (mod 2*h)
        if xj % gcd(x, 2*w) != 0: continue
        if yj % gcd(y, 2*w) != 0: continue
        # tot += c * sum(1 for i in range(k) if xj == (-i*x) % (2*w) and yj == (-i*y) % (2*h))

        ## OR, EQUIVALENTLY
        g = gcd(x, 2*w)
        ## -xj//g = i*x//g (mod 2*w//g) and yj = i*y (mod 2*h)
        ## -xj//g * (x//g)**{-1} = i (mod 2*w//g) and yj = i*y (mod 2*h)
        inv = pow(x//g, -1, 2*w//g)
        ## i = a (mod m1) and yj = i*y (mod 2*h)
        m1 = 2*w//g
        a = (-xj//g * inv) % m1

        ## THE SAME FOR y.
        g = gcd(y, 2*h)
        inv = pow(y//g, -1, 2*h//g)
        ## i = a (mod m1) and i = b (mod m2)
        m2 = 2*h//g
        b = (-yj//g * inv) % m2

        ## i = a+l*m1
        ## (a+l*m1) % m2 = b
        ## (l*m1) % m2 = (b-a) % m2
        g = gcd(m1, m2)
        if (b-a) % g != 0: continue
        lc = m1 * m2 // g
        ## (l*m1//g) % (m2//g) = (b-a)//g % (m2//g)
        ## l % (m2//g) = (b-a)//g * (m1//g)^{-1} % (m2//g)
        l = pow(m1//g, -1, m2//g) * (b-a) // g
        i = (a + l*m1) % lc
        ## i = i mod lc
        d, m = divmod(k, lc)
        tot += c * (d + (i < m))

        # print(i, lc)

        # tot += c * sum(1 for i in range(k) if xj == (-i*x) % (2*w) and yj == (-i*y) % (2*h))
        # tot += c * sum(1 for i in range(a, k, m1) if xj == (-i*x) % (2*w) and yj == (-i*y) % (2*h))
        # tot += c * sum(1 for i in range(a, k, m1) if yj == (-i*y) % (2*h))
        # tot += c * sum(1 for i in range(a, k, m1) if i % m2 == b)

    # g1, g2 = abs(gcd(m1, x)), abs(gcd(m2, y))
    # m1 //= g1
    # x //= g1
    # m2 //= g2
    # y //= g2
    # ix = pow(-x, -1, m1)
    # iy = pow(-y, -1, m2)
    # tot = 0
    # cache = {}
    # for (xj, yj), c in cnt.items():
    #     # print((xj * ix) % m1, (yj * iy) % m2, m1, m2)
    #     n = [m1, m2]
    #     a = [(xj * ix) % m1, (yj * iy) % m2]
    #     g = gcd(n[0], n[1])
    #     if a[0] % g != a[1] % g:
    #         continue
    #     elif n[0] == n[1]:
    #         m = n[0]
    #         r = a[0]
    #     else:
    #         n[0] //= g
    #         m = n[0] * n[1]
    #         r = chinese_remainder(n, a)
    #
    #     div, mod = divmod(k, m)
    #     num = c * (div + (mod > r))
    #     tot += max(0, num - cache.get((m, r), 0))
    #     cache[(m, r)] = max(num, cache.get((m, r), 0))
    #     print(m, r, divmod(k, m), c)

    # for i in range(k):
    #     tot += cnt[((-i*x) % (2*w), (-i*y) % (2*h))]

    # print(cnt)
    return tot

if __name__ == "__main__":
    # Read in input:
    t = int(input())

    # Call solution:
    for _ in range(t):
        _, k, w, h = read_array(int)
        s = input().strip()
        ans = solve(k, w, h, s)
        print(ans)

**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
7 123456789999 3 2
ULULURD
```


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Dyn-scripted Robot (Hard Version)
time_limit_ms: 3000
memory_limit_mb: 256
Description: This is the hard version of the problem. The only difference is that in this version $k \le 10^{12}$. You can make hacks only if both versions of the problem are solved.

Given a $w \times h$ rectangle on the $Oxy$ plane, with points $(0, 0)$ at the bottom-left and $(w, h)$ at the top-right of the rectangle.

You also have a robot initially at point $(0, 0)$ and a script $s$ of $n$ characters. Each character is either L, R, U, or D, which tells the robot to move left, right, up, or down respectively.

The robot can only move inside the rectangle; otherwise, it will change the script $s$ as follows:

  * If it tries to move outside a vertical border, it changes all L characters to R's (and vice versa, all R's to L's).    * If it tries to move outside a horizontal border, it changes all U characters to D's (and vice versa, all D's to U's).

Then, it will execute the changed script starting from the character which it couldn't execute.

![](CDN_BASE_URL/ff5ae9758c965c2d8398c936e9581dab) An example of the robot's movement process, $s = \texttt{"ULULURD"}$

The script $s$ will be executed for $k$ times continuously. All changes to the string $s$ will be retained even when it is repeated. During this process, how many times will the robot move to the point $(0, 0)$ in total? Note that the initial position does NOT count.

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 four integers $n$, $k$, $w$, and $h$ ($1 \le n, w, h \le 10^6$; $1 \le k \le 10^{12}$).

The second line contains a single string $s$ of size $n$ ($s_i \in \\{\texttt{L}, \texttt{R}, \texttt{U}, \texttt{D}\\}$) — the script to be executed.

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^6$.

Output: For each test case, print a single integer — the number of times the robot reaches $(0, 0)$ when executing script $s$ for $k$ times continuously.

Examples:
input:
6
2 4 2 2
UR
4 2 1 1
LLDD
6 3 3 1
RLRRRL
5 6 3 3
RUURD
7 5 3 4
RRDLUUU
7 123456789999 3 2
ULULURD
output:
1
4
3
1
1
41152263332

Note: In the first test case, the robot only moves up and right for the first two executions. After that, it occupies the position $(2, 2)$. For the next two executions, it moves down and left and finishes at $(0, 0)$. So the answer is $1$.

In the second test case, each time executing the script the robot visits the origin twice. And since $k=2$, it visits the origin $2 \cdot 2 = 4$ times overall.

![](CDN_BASE_URL/ea799abf84f8a212d5a0d782be4d5e9c)

In the third test case, the visualization is shown as below:

![](CDN_BASE_URL/c6a5be14982b3d57a5103783598d4683)

Buggy Code:
# -*- coding: utf-8 -*-
"""
Created on Mon Aug  5 01:38:12 2024

@author: hambu
"""

from math import lcm

T = int(input())

for _ in range(T):
    n, k, w, h = map(int, input().split())
    S = list(input())

    x = 0
    y = 0

    visits = dict()

    for s in S:
        if s == "L":
            x = (x-1)%(2*w)
        elif s == "R":
            x = (x+1)%(2*w)
        elif s == "U":
            y = (y+1)%(2*h)
        else:
            y = (y-1)%(2*h)

        if (x,y) in visits:
            visits[(x,y)] += 1
        else:
            visits[(x,y)] = 1
    ex, ey = x, y # End values

    answers = []
    rx, ry = 0, 0

    loopx, loopy = 1, 1
    if ex:
        loopx = lcm(2*w, ex) // ex
    if ey:
        loopy = lcm(2*h, ey) // ey
    loopl = lcm(loopx, loopy)

    for _ in range(loopl):
        if (rx, ry) in visits:
            answers.append(visits[(rx,ry)])
        else:
            answers.append(0)
        rx = (rx-ex)%(2*w)
        ry = (ry-ey)%(2*h)

    loops = sum(answers)
    answer = k//loopl * loops + sum(answers[:k%loopl])
    print(answer)

**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
10 1000000000000 10 10
RRRRRRRRRR
```


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Dyn-scripted Robot (Hard Version)
time_limit_ms: 3000
memory_limit_mb: 256
Description: This is the hard version of the problem. The only difference is that in this version $k \le 10^{12}$. You can make hacks only if both versions of the problem are solved.

Given a $w \times h$ rectangle on the $Oxy$ plane, with points $(0, 0)$ at the bottom-left and $(w, h)$ at the top-right of the rectangle.

You also have a robot initially at point $(0, 0)$ and a script $s$ of $n$ characters. Each character is either L, R, U, or D, which tells the robot to move left, right, up, or down respectively.

The robot can only move inside the rectangle; otherwise, it will change the script $s$ as follows:

  * If it tries to move outside a vertical border, it changes all L characters to R's (and vice versa, all R's to L's).    * If it tries to move outside a horizontal border, it changes all U characters to D's (and vice versa, all D's to U's).

Then, it will execute the changed script starting from the character which it couldn't execute.

![](CDN_BASE_URL/ff5ae9758c965c2d8398c936e9581dab) An example of the robot's movement process, $s = \texttt{"ULULURD"}$

The script $s$ will be executed for $k$ times continuously. All changes to the string $s$ will be retained even when it is repeated. During this process, how many times will the robot move to the point $(0, 0)$ in total? Note that the initial position does NOT count.

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 four integers $n$, $k$, $w$, and $h$ ($1 \le n, w, h \le 10^6$; $1 \le k \le 10^{12}$).

The second line contains a single string $s$ of size $n$ ($s_i \in \\{\texttt{L}, \texttt{R}, \texttt{U}, \texttt{D}\\}$) — the script to be executed.

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^6$.

Output: For each test case, print a single integer — the number of times the robot reaches $(0, 0)$ when executing script $s$ for $k$ times continuously.

Examples:
input:
6
2 4 2 2
UR
4 2 1 1
LLDD
6 3 3 1
RLRRRL
5 6 3 3
RUURD
7 5 3 4
RRDLUUU
7 123456789999 3 2
ULULURD
output:
1
4
3
1
1
41152263332

Note: In the first test case, the robot only moves up and right for the first two executions. After that, it occupies the position $(2, 2)$. For the next two executions, it moves down and left and finishes at $(0, 0)$. So the answer is $1$.

In the second test case, each time executing the script the robot visits the origin twice. And since $k=2$, it visits the origin $2 \cdot 2 = 4$ times overall.

![](CDN_BASE_URL/ea799abf84f8a212d5a0d782be4d5e9c)

In the third test case, the visualization is shown as below:

![](CDN_BASE_URL/c6a5be14982b3d57a5103783598d4683)

Buggy Code:
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include "bits/stdc++.h"
using namespace std;
using ll = long long int;
mt19937_64 RNG(chrono::high_resolution_clock::now().time_since_epoch().count());

ll euclid(ll a, ll b, ll &x, ll &y) {
	if (!b) return x = 1, y = 0, a;
	ll d = euclid(b, a % b, y, x);
	return y -= a/b * x, d;
}

ll crt(ll a, ll m, ll b, ll n) {
	if (n > m) swap(a, b), swap(m, n);
	ll x, y, g = euclid(m, n, x, y);

    // assert((a - b) % g == 0); // else no solution
    if ((a - b) % g) return -1;

    x = (b - a) % n * x % n / g * m + a;
	return x < 0 ? x + m*n/g : x;
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(0);

    int t; cin >> t;
    while (t--) {
        ll n, k, w, h; cin >> n >> k >> w >> h;
        string s; cin >> s;
        ll dx = 0, dy = 0;
        for (auto c : s) {
            dx += c == 'R';
            dx -= c == 'L';
            dy += c == 'U';
            dy -= c == 'D';
        }

        w *= 2;
        h *= 2;
        dx = (dx%w + w) % w;
        dy = (dy%h + h) % h;

        auto ct = [&] (ll a, ll b, ll m) {
            // number of solutions to ax = b (mod m)
            ll g = gcd(a, m);
            if (b%g) return 0ll;
            return g;
        };

        ll x = 0, y = 0, ans = 0;
        for (auto c : s) {
            x -= c == 'R';
            x += c == 'L';
            y -= c == 'U';
            y += c == 'D';
            x = (x%w + w) % w;
            y = (y%h + h) % h;

            if (dx == 0 and dy == 0) {
                if (x == 0 and y == 0) ans += k;
                continue;
            }
            if (dx == 0) {
                if (x) continue;
                // y + k*dy = 0 (mod h)
                ll g = ct(dy, y, h);
                if (g == 0) continue;

                ll a = dy/g, b = y/g, m = h/g;
                ll inv, tmp;
                euclid(a, m, inv, tmp);
                inv = (inv%m + m)%m;

                ll X = (inv * b) % m;
                if (X < k) ans += (k-1 - X)/m + 1;
                continue;
            }
            if (dy == 0) {
                if (y) continue;
                ll g = ct(dx, x, w);
                if (g == 0) continue;

                ll a = dx/g, b = x/g, m = w/g;
                ll inv, tmp;
                euclid(a, m, inv, tmp);
                inv = (inv%m + m)%m;

                ll X = (inv * b) % m;
                if (X < k) ans += (k-1 - X)/m + 1;
                continue;
            }

            /**
             * x + k*dx = 0 (mod w)
             * y + k*dy = 0 (mod h)
             *
             */

            ll s1 = ct(dx, x, w), s2 = ct(dy, y, h);
            if (s1 == 0 or s2 == 0) continue;

            ll m1 = w/s1, m2 = h/s2;
            ll inv1 = 0, inv2 = 0, tmp = 0;
            euclid(dx/s1, m1, inv1, tmp);
            tmp = 0;
            euclid(dy/s2, m2, inv2, tmp);
            inv1 = (inv1%m1 + m1)%m1;
            inv2 = (inv2%m2 + m2)%m2;
            ll k1 = (inv1 * (x/s1))%w, k2 = (inv2 * (y/s2))%h;

            // assert(((dx/s1)*inv1)%m1 == 1);
            // assert(((dy/s2)*inv2)%m2 == 1);

            /**
             * k = k1 (mod m1)
             * k = k2 (mod m2)
             */

            ll K = crt(k1, m1, k2, m2);
            if (K == -1) continue;

            ll L = lcm(m1, m2);

            // K + s*L <= k-1 --> sL <= k-1 - K --> s <= (k-1 - K)/L
            if (K >= k) continue;
            ans += (k-1 - K)/L + 1;
        }
        cout << ans << '\n';

        // {
        //     ll ans2 = 0;
        //     ll X = 0, Y = 0;
        //     for (int i = 0; i < k; ++i) {
        //         for (auto c : s) {
        //             X += c == 'R';
        //             X -= c == 'L';
        //             Y += c == 'U';
        //             Y -= c == 'D';
        //             X = (X%w + w) % w;
        //             Y = (Y%h + h) % h;

        //             ans2 += (X == 0) and (Y == 0);
        //         }
        //     }
        //     cerr << ans2 << '\n';
        //     if (ans != ans2) {
        //         cerr << n << ' ' << k << ' ' << w << ' ' << h << '\n';
        //         cerr << s << '\n';
        //         cerr << ans << ' ' << ans2 << '\n';
        //         assert(false);
        //     }
        // }
    }
}

**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 algorithm to fail. Here are the steps to think through the problem:

1. **Understanding the Bug**: The buggy code seems to have issues with handling the periodic nature of the robot's movements and the constraints of the rectangle. It uses the Chinese Remainder Theorem (CRT) and modular arithmetic to find the number of times the robot returns to the origin. However, it might not correctly handle cases where the robot's movement causes it to change the script in a way that affects the periodicity.

2. **Edge Cases**:
   - **Small Rectangle**: A small rectangle can make the periodicity more apparent and easier to debug.
   - **Script with Few Movements**: A short script can help in understanding the behavior of the robot more clearly.
   - **Large k**: A large value of \( k \) can help in exposing issues with the periodicity and the CRT calculations.

3. **Example Input**:
   - **t = 1**: Single test case.
   - **n = 4**: Short script.
   - **k = 1000000000000**: Large value of \( k \) to test the periodicity.
   - **w = 2**: Small width.
   - **h = 2**: Small height.
   - **s = "LLRR"**: Script that causes the robot to move left and right, which will change the script and affect the periodicity.

Given these considerations, the test input is:

```plaintext
1
4 1000000000000 2 2
LLRR
```

This input is designed to test the periodicity and the script change behavior, which are potential sources of bugs in the provided code.


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Dyn-scripted Robot (Hard Version)
time_limit_ms: 3000
memory_limit_mb: 256
Description: This is the hard version of the problem. The only difference is that in this version $k \le 10^{12}$. You can make hacks only if both versions of the problem are solved.

Given a $w \times h$ rectangle on the $Oxy$ plane, with points $(0, 0)$ at the bottom-left and $(w, h)$ at the top-right of the rectangle.

You also have a robot initially at point $(0, 0)$ and a script $s$ of $n$ characters. Each character is either L, R, U, or D, which tells the robot to move left, right, up, or down respectively.

The robot can only move inside the rectangle; otherwise, it will change the script $s$ as follows:

  * If it tries to move outside a vertical border, it changes all L characters to R's (and vice versa, all R's to L's).    * If it tries to move outside a horizontal border, it changes all U characters to D's (and vice versa, all D's to U's).

Then, it will execute the changed script starting from the character which it couldn't execute.

![](CDN_BASE_URL/ff5ae9758c965c2d8398c936e9581dab) An example of the robot's movement process, $s = \texttt{"ULULURD"}$

The script $s$ will be executed for $k$ times continuously. All changes to the string $s$ will be retained even when it is repeated. During this process, how many times will the robot move to the point $(0, 0)$ in total? Note that the initial position does NOT count.

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 four integers $n$, $k$, $w$, and $h$ ($1 \le n, w, h \le 10^6$; $1 \le k \le 10^{12}$).

The second line contains a single string $s$ of size $n$ ($s_i \in \\{\texttt{L}, \texttt{R}, \texttt{U}, \texttt{D}\\}$) — the script to be executed.

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^6$.

Output: For each test case, print a single integer — the number of times the robot reaches $(0, 0)$ when executing script $s$ for $k$ times continuously.

Examples:
input:
6
2 4 2 2
UR
4 2 1 1
LLDD
6 3 3 1
RLRRRL
5 6 3 3
RUURD
7 5 3 4
RRDLUUU
7 123456789999 3 2
ULULURD
output:
1
4
3
1
1
41152263332

Note: In the first test case, the robot only moves up and right for the first two executions. After that, it occupies the position $(2, 2)$. For the next two executions, it moves down and left and finishes at $(0, 0)$. So the answer is $1$.

In the second test case, each time executing the script the robot visits the origin twice. And since $k=2$, it visits the origin $2 \cdot 2 = 4$ times overall.

![](CDN_BASE_URL/ea799abf84f8a212d5a0d782be4d5e9c)

In the third test case, the visualization is shown as below:

![](CDN_BASE_URL/c6a5be14982b3d57a5103783598d4683)

Buggy Code:
#include <bits/stdc++.h>
using i64 = long long;
#define int long long

#define pb push_back
using std::max, std::min;
using std::cin, std::cout, std::string, std::vector;
int read(int x = 0, int f = 0, char ch = getchar()) {
    while (ch < 48 or 57 < ch) f = ch == 45, ch = getchar();
    while(48 <= ch and ch <= 57) x = x * 10 + ch - 48, ch = getchar();
    return f ? -x : x;
}

i64 exgcd(i64 a, i64 b, i64 &x, i64 &y) {
    if (b == 0) {
        x = 1, y = 0;
        return a;
    }
    i64 g = exgcd(b, a % b, y, x);
    y -= a / b * x;
    return g;
}
// ax + b = 0 (mod m)
std::pair<i64, i64> sol(i64 a, i64 b, i64 m) {
    assert(m > 0);
    b *= -1;
    i64 x, y;
    i64 g = exgcd(a, m, x, y);
    if (g < 0) {
        g *= -1;
        x *= -1;
        y *= -1;
    }
    if (b % g != 0) {
        return {-1, -1};
    }
    x = x * (b / g) % (m / g);
    if (x < 0) {
        x += m / g;
    }
    return {x, m / g};
}

void solve() {
    i64 n = read(), k = read();
    i64 w = read(), h = read();

    w <<= 1, h <<= 1;
    string s; cin >> s;

    vector<std::pair<i64, i64>> buk;
    i64 x = 0, y = 0;
    for (auto c : s) {
        if (c == 'U') y++;
        if (c == 'D') y--;
        if (c == 'L') x--;
        if (c == 'R') x++;
        x = (x + w) % w;
        y = (y + h) % h;
        buk.emplace_back(x, y);
    }
    auto [dx, dy] = buk.back();

    i64 ans = 0;

    for (auto [x, y] : buk) {
        /*
        x + t dx = 0 (mod 2w)
        y + t dy = 0 (mod 2h)
        t = a1 (mod m1)
        t = a2 (mod m2)

        t = k * m1 + a1 = a2 (mod m2)
        k * m1 + a1 - a2 = 0 (mod m2)
        */
        auto [a1, m1] = sol(dx, x, w);
        auto [a2, m2] = sol(dy, y, h);

        if (a1 == -1 or a2 == -1) continue;

        auto [X, m] = sol(m1, a1 - a2, m2);
        if (X == -1) continue;

        m *= m1;
        X = (X * m1 + a1) % m;
        if (k > X) {
            ans += (k - 1 - x) / m + 1;
        }
    }
    cout << ans << '\n';
}

signed main() {
    for (int T = read(); T--; solve());
    // 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
7 5 3 4
RRDLUUU
```


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Dyn-scripted Robot (Hard Version)
time_limit_ms: 3000
memory_limit_mb: 256
Description: This is the hard version of the problem. The only difference is that in this version $k \le 10^{12}$. You can make hacks only if both versions of the problem are solved.

Given a $w \times h$ rectangle on the $Oxy$ plane, with points $(0, 0)$ at the bottom-left and $(w, h)$ at the top-right of the rectangle.

You also have a robot initially at point $(0, 0)$ and a script $s$ of $n$ characters. Each character is either L, R, U, or D, which tells the robot to move left, right, up, or down respectively.

The robot can only move inside the rectangle; otherwise, it will change the script $s$ as follows:

  * If it tries to move outside a vertical border, it changes all L characters to R's (and vice versa, all R's to L's).    * If it tries to move outside a horizontal border, it changes all U characters to D's (and vice versa, all D's to U's).

Then, it will execute the changed script starting from the character which it couldn't execute.

![](CDN_BASE_URL/ff5ae9758c965c2d8398c936e9581dab) An example of the robot's movement process, $s = \texttt{"ULULURD"}$

The script $s$ will be executed for $k$ times continuously. All changes to the string $s$ will be retained even when it is repeated. During this process, how many times will the robot move to the point $(0, 0)$ in total? Note that the initial position does NOT count.

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 four integers $n$, $k$, $w$, and $h$ ($1 \le n, w, h \le 10^6$; $1 \le k \le 10^{12}$).

The second line contains a single string $s$ of size $n$ ($s_i \in \\{\texttt{L}, \texttt{R}, \texttt{U}, \texttt{D}\\}$) — the script to be executed.

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^6$.

Output: For each test case, print a single integer — the number of times the robot reaches $(0, 0)$ when executing script $s$ for $k$ times continuously.

Examples:
input:
6
2 4 2 2
UR
4 2 1 1
LLDD
6 3 3 1
RLRRRL
5 6 3 3
RUURD
7 5 3 4
RRDLUUU
7 123456789999 3 2
ULULURD
output:
1
4
3
1
1
41152263332

Note: In the first test case, the robot only moves up and right for the first two executions. After that, it occupies the position $(2, 2)$. For the next two executions, it moves down and left and finishes at $(0, 0)$. So the answer is $1$.

In the second test case, each time executing the script the robot visits the origin twice. And since $k=2$, it visits the origin $2 \cdot 2 = 4$ times overall.

![](CDN_BASE_URL/ea799abf84f8a212d5a0d782be4d5e9c)

In the third test case, the visualization is shown as below:

![](CDN_BASE_URL/c6a5be14982b3d57a5103783598d4683)

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

vector<int>prime_divs;

int binp(int a,int b,int modd){
    int res=1;
    while(b){
        if(b&1)res*=a,res%=modd;
        a*=a;
        a%=modd;
        b/=2;
    }
    return res;
}
vector<pair<int,int>>v1,v2;

int cong_solver2(vector<pair<pair<int,int>,int>>congs){
    // for(auto v:congs)cout<<v.first<<"--"<<v.second<<"\n";
    int M = 1;
    for (auto v:congs) M *=v.first.first;
    int solution = 0;
    for (auto v : congs) {
        int a_i = v.first.second,M_i=M/v.first.first,N_i=binp(M_i,v.second-1,v.first.first);
        solution = (solution + a_i * M_i* N_i) % M;
    }
    return solution;
}
int cong(int a,int b){
    return 1;
    vector<pair<int,int>>temp1=v1,temp2=v2;
    vector<pair<int,int>>congs;
    while((!temp1.empty()) && (!temp2.empty())){
        int p1=temp1.back().first,p2=temp2.back().first;
        if(p1==p2){
            int pp1=temp1.back().second,pp2=temp2.back().second;
            if(pp1<=pp2){
                if(b%pp1==a%pp1)congs.push_back({b%pp2,pp2});
                else return -1;
            }
            else {
                if(a%pp2==b%pp2)congs.push_back({a%pp1,pp1});
                else return -1;
            }
            temp1.pop_back();
            temp2.pop_back();
        }
        else if(p1>p2){
            congs.push_back({a%temp1.back().second,temp1.back().second});
            temp1.pop_back();
        }
        else{
            congs.push_back({b%temp2.back().second,temp2.back().second});
            temp2.pop_back();
        }
    }
    while(!temp1.empty()){
        congs.push_back({b%temp2.back().second,temp2.back().second});
        temp2.pop_back();
    }
    while(!temp2.empty()){
        congs.push_back({b%temp2.back().second,temp2.back().second});
        temp2.pop_back();
    }
    // return solve_cong(congs);
}
vector<int>prims(int n){
    vector<int>res;
    for(int i=2;i*i<n+1;i++){
        if(n%i==0){
            int curr=1;
            while(n%i==0)n/=i,curr*=i;
            res.push_back(i);
        }
    }
    if(n>1)res.push_back(n);
    return res;
}

int cong_solver1(int mod1,int n1,int mod2,int n2){
    vector<pair<pair<int,int>,int>>congs;
    for(auto v:prime_divs){
        int val1=1,val2=1;
        while(n1%v==0)val1*=v,n1/=v;
        while(n2%v==0)val2*=v,n2/=v;
        int phi=max(val1,val2)*(v-1);
        phi/=v;
        if(val1>val2){
            if(mod1%val2==mod2%val2)congs.push_back({{val1,mod1%val1},phi});
            else return -1;
        }
        else{
            if(mod1%val1==mod2%val1)congs.push_back({{val2,mod2%val2},phi});
            else return -1;
        }
    }
    return cong_solver2(congs);

}
void solve(){
    int n,k,xmax,ymax;
    cin>>n>>k>>xmax>>ymax;
    map<pair<int,int>,int>mp;
    string s;
    cin>>s;
    int x=0,y=0;
    xmax*=2,ymax*=2;
    for(auto v:s){
        if(v=='L')x--;
        else if(v=='R')x++;
        else if(v=='U')y++;
        else  y--;
        x+=xmax,y+=ymax;
        x%=xmax,y%=ymax;
        mp[{x,y}]++;
        // cout<<x<<" "<<y<<"\n";
    }
    long long ans=0;
    int a1=x,n1=xmax,g1=__gcd(a1,n1);

    a1/=g1,n1/=g1;
    // int inv1=binp(a1,n1-2,n1);
    int a2=y,n2=ymax,g2=__gcd(a2,n2);
    a2/=g2,n2/=g2;
    // int inv2=binp(a2,n2-2,n2);
    int lcm=(n1*n2)/__gcd(n1,n2);
    vector<int>p1=prims(n1),p2=prims(n2),p;
    while((!p1.empty()) && (!p2.empty())){
        if(p1.back()>p2.back())p.push_back(p1.back()),p1.pop_back();
        else if (p1.back()<p2.back())p.push_back(p2.back()),p2.pop_back();
        else p.push_back(p2.back()),p1.pop_back(),p2.pop_back();
    }
    while(!p1.empty())p.push_back(p1.back()),p1.pop_back();
    while(!p2.empty())p.push_back(p2.back()),p2.pop_back();
    int phi1=n1,phi2=n2;
    for(auto v:p){
        if(n1%v==0)phi1=(phi1*(v-1))/v;
        if(n2%v==0)phi2=(phi2*(v-2))/v;
    }
    int inv1=binp(a1,phi1-1,n1),inv2=binp(a2,phi2-1,n2);
    k--;
    prime_divs=p;
    for(auto v:mp){
        int cx=v.first.first,cy=v.first.second,val=v.second;
        // cout<<cx<<" "<<cy<<" hwew\n";
        int remx=(xmax-cx)%xmax,remy=(ymax-cy)%ymax;
        // cout<<remx<<" "<<remy<<"\n";
        // if(mp.find({remx,remy})==mp.end())continue;
        int b1=remx,b2=remy;
        if((b1%g1)+(b2%g2))continue;
        b1/=g1;
        b2/=g2;
        int mod1=(b1*inv1)%n1;
        int mod2=(b2*inv2)%n2;
        // cout<<mod1<<" "<<n1<<" "<<mod2<<" "<<n2<<"\n";
        int p1=cong_solver1(mod1,n1,mod2,n2);
        if(p1!=-1){
            // cout<<"here "<<p1<<" "<<lcm<<"\n";
            // cout<<val<<"\n";
            int num=(k-p1+lcm)/lcm;
            ans+=num*val;
        }
        // cout<<p1<<"\n";
        // cout<<mod1<<" -- "<<n1<<"\n";
        // cout<<mod2<<" -- "<<n2<<"\n";
    }
    // if(ans==41152263334)ans-=2;
    cout<<ans<<"\n";

}

int32_t main(){
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int test=1;
    cin>>test;
    for(int tst=1;tst<test+1;tst++){
        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:
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 maximize the failure probability. Here are the steps to consider:

1. **Edge Cases for Dimensions and Movements**:
   - Test with minimum and maximum values for \( w \) and \( h \).
   - Test with a script that causes the robot to hit the borders and trigger the script modifications.

2. **Large \( k \)**:
   - Test with a large value of \( k \) to ensure the algorithm can handle it efficiently and correctly.

3. **Special Scripts**:
   - Test with scripts that have a high frequency of border hits.
   - Test with scripts that cause the robot to return to the origin multiple times in a single execution.

4. **Multiple Test Cases**:
   - Include multiple test cases to cover different scenarios.

Given these considerations, here is a small-scale test input that is complete and valid:

```plaintext
4
2 4 2 2
UR
4 2 1 1
LLDD
6 3 3 1
RLRRRL
7 123456789999 3 2
ULULURD
```

This input includes:
- A simple case with a small \( k \) and \( w \times h \) (2x2 rectangle).
- A case with a small \( w \times h \) (1x1 rectangle) and a script that causes frequent border hits.
- A case with a larger \( w \times h \) (3x1 rectangle) and a script that causes the robot to move back and forth.
- A case with a very large \( k \) (123456789999) and a script that causes the robot to move to the origin multiple times.

This input should help expose any bugs in the buggy code, especially in handling large \( k \) values and frequent border hits.


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Dyn-scripted Robot (Hard Version)
time_limit_ms: 3000
memory_limit_mb: 256
Description: This is the hard version of the problem. The only difference is that in this version $k \le 10^{12}$. You can make hacks only if both versions of the problem are solved.

Given a $w \times h$ rectangle on the $Oxy$ plane, with points $(0, 0)$ at the bottom-left and $(w, h)$ at the top-right of the rectangle.

You also have a robot initially at point $(0, 0)$ and a script $s$ of $n$ characters. Each character is either L, R, U, or D, which tells the robot to move left, right, up, or down respectively.

The robot can only move inside the rectangle; otherwise, it will change the script $s$ as follows:

  * If it tries to move outside a vertical border, it changes all L characters to R's (and vice versa, all R's to L's).    * If it tries to move outside a horizontal border, it changes all U characters to D's (and vice versa, all D's to U's).

Then, it will execute the changed script starting from the character which it couldn't execute.

![](CDN_BASE_URL/ff5ae9758c965c2d8398c936e9581dab) An example of the robot's movement process, $s = \texttt{"ULULURD"}$

The script $s$ will be executed for $k$ times continuously. All changes to the string $s$ will be retained even when it is repeated. During this process, how many times will the robot move to the point $(0, 0)$ in total? Note that the initial position does NOT count.

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 four integers $n$, $k$, $w$, and $h$ ($1 \le n, w, h \le 10^6$; $1 \le k \le 10^{12}$).

The second line contains a single string $s$ of size $n$ ($s_i \in \\{\texttt{L}, \texttt{R}, \texttt{U}, \texttt{D}\\}$) — the script to be executed.

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^6$.

Output: For each test case, print a single integer — the number of times the robot reaches $(0, 0)$ when executing script $s$ for $k$ times continuously.

Examples:
input:
6
2 4 2 2
UR
4 2 1 1
LLDD
6 3 3 1
RLRRRL
5 6 3 3
RUURD
7 5 3 4
RRDLUUU
7 123456789999 3 2
ULULURD
output:
1
4
3
1
1
41152263332

Note: In the first test case, the robot only moves up and right for the first two executions. After that, it occupies the position $(2, 2)$. For the next two executions, it moves down and left and finishes at $(0, 0)$. So the answer is $1$.

In the second test case, each time executing the script the robot visits the origin twice. And since $k=2$, it visits the origin $2 \cdot 2 = 4$ times overall.

![](CDN_BASE_URL/ea799abf84f8a212d5a0d782be4d5e9c)

In the third test case, the visualization is shown as below:

![](CDN_BASE_URL/c6a5be14982b3d57a5103783598d4683)

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

vector<int>prime_divs;
bool prn=false;

int binp(int a,int b,int modd){
    int res=1;
    while(b){
        if(b&1)res*=a,res%=modd;
        a*=a;
        a%=modd;
        b/=2;
    }
    return res;
}
vector<pair<int,int>>v1,v2;

int cong_solver2(vector<pair<pair<int,int>,int>>congs){
    // for(auto v:congs)cout<<v.first<<"--"<<v.second<<"\n";
    int M = 1;
    for (auto v:congs) M *=v.first.first;
    int solution = 0;
    for (auto v : congs) {
        int a_i = v.first.second,M_i=M/v.first.first,N_i=binp(M_i,v.second-1,v.first.first);
        solution = (solution + a_i * M_i* N_i) % M;
    }
    return solution;
}
int cong(int a,int b){
    return 1;
    vector<pair<int,int>>temp1=v1,temp2=v2;
    vector<pair<int,int>>congs;
    while((!temp1.empty()) && (!temp2.empty())){
        int p1=temp1.back().first,p2=temp2.back().first;
        if(p1==p2){
            int pp1=temp1.back().second,pp2=temp2.back().second;
            if(pp1<=pp2){
                if(b%pp1==a%pp1)congs.push_back({b%pp2,pp2});
                else return -1;
            }
            else {
                if(a%pp2==b%pp2)congs.push_back({a%pp1,pp1});
                else return -1;
            }
            temp1.pop_back();
            temp2.pop_back();
        }
        else if(p1>p2){
            congs.push_back({a%temp1.back().second,temp1.back().second});
            temp1.pop_back();
        }
        else{
            congs.push_back({b%temp2.back().second,temp2.back().second});
            temp2.pop_back();
        }
    }
    while(!temp1.empty()){
        congs.push_back({b%temp2.back().second,temp2.back().second});
        temp2.pop_back();
    }
    while(!temp2.empty()){
        congs.push_back({b%temp2.back().second,temp2.back().second});
        temp2.pop_back();
    }
    // return solve_cong(congs);
}
vector<int>prims(int n){
    vector<int>res;
    for(int i=2;i*i<n+1;i++){
        if(n%i==0){
            int curr=1;
            while(n%i==0)n/=i,curr*=i;
            res.push_back(i);
        }
    }
    if(n>1)res.push_back(n);
    return res;
}

int cong_solver1(int mod1,int n1,int mod2,int n2){
    vector<pair<pair<int,int>,int>>congs;
    for(auto v:prime_divs){
        int val1=1,val2=1;
        while(n1%v==0)val1*=v,n1/=v;
        while(n2%v==0)val2*=v,n2/=v;
        int phi=max(val1,val2)*(v-1);
        phi/=v;
        if(val1>val2){
            if(mod1%val2==mod2%val2)congs.push_back({{val1,mod1%val1},phi});
            else return -1;
        }
        else{
            if(mod1%val1==mod2%val1)congs.push_back({{val2,mod2%val2},phi});
            else return -1;
        }
    }
    return cong_solver2(congs);

}
void solve(){
    int n,k,xmax,ymax;
    cin>>n>>k>>xmax>>ymax;
    map<pair<int,int>,int>mp;
    string s;
    cin>>s;
    if(prn)cout<<n<<"--"<<k<<"--"<<xmax<<"--"<<ymax<<"--"<<s<<"\n";
    int x=0,y=0;
    xmax*=2,ymax*=2;
    for(auto v:s){
        if(v=='L')x--;
        else if(v=='R')x++;
        else if(v=='U')y++;
        else  y--;
        x+=xmax,y+=ymax;
        x%=xmax,y%=ymax;
        mp[{x,y}]++;
        // cout<<x<<" "<<y<<"\n";
    }
    long long ans=0;
    int a1=x,n1=xmax,g1=__gcd(a1,n1);

    a1/=g1,n1/=g1;
    // int inv1=binp(a1,n1-2,n1);
    int a2=y,n2=ymax,g2=__gcd(a2,n2);
    a2/=g2,n2/=g2;
    // int inv2=binp(a2,n2-2,n2);
    int lcm=(n1*n2)/__gcd(n1,n2);
    vector<int>p1=prims(n1),p2=prims(n2),p;
    while((!p1.empty()) && (!p2.empty())){
        if(p1.back()>p2.back())p.push_back(p1.back()),p1.pop_back();
        else if (p1.back()<p2.back())p.push_back(p2.back()),p2.pop_back();
        else p.push_back(p2.back()),p1.pop_back(),p2.pop_back();
    }
    while(!p1.empty())p.push_back(p1.back()),p1.pop_back();
    while(!p2.empty())p.push_back(p2.back()),p2.pop_back();
    int phi1=n1,phi2=n2;
    for(auto v:p){
        if(n1%v==0)phi1=(phi1*(v-1))/v;
        if(n2%v==0)phi2=(phi2*(v-2))/v;
    }
    int inv1=binp(a1,phi1-1,n1),inv2=binp(a2,phi2-1,n2);
    k--;
    prime_divs=p;
    for(auto v:mp){
        int cx=v.first.first,cy=v.first.second,val=v.second;
        // cout<<cx<<" "<<cy<<" hwew\n";
        int remx=(xmax-cx)%xmax,remy=(ymax-cy)%ymax;
        // cout<<remx<<" "<<remy<<"\n";
        // if(mp.find({remx,remy})==mp.end())continue;
        int b1=remx,b2=remy;
        if((b1%g1)+(b2%g2))continue;
        b1/=g1;
        b2/=g2;
        int mod1=(b1*inv1)%n1;
        int mod2=(b2*inv2)%n2;
        // cout<<mod1<<" "<<n1<<" "<<mod2<<" "<<n2<<"\n";
        int p1=cong_solver1(mod1,n1,mod2,n2);
        if(p1!=-1){
            // cout<<"here "<<p1<<" "<<lcm<<"\n";
            // cout<<val<<"\n";
            int num=(k-p1+lcm)/lcm;
            ans+=num*val;
        }
        // cout<<p1<<"\n";
        // cout<<mod1<<" -- "<<n1<<"\n";
        // cout<<mod2<<" -- "<<n2<<"\n";
    }
    // if(ans==41152263334)ans-=2;
    cout<<ans<<"\n";

}

int32_t main(){
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int test=1;
    cin>>test;
    for(int tst=1;tst<test+1;tst++){
        if(tst==40)prn=true;
        else prn=false;
        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
6
2 4 2 2
UR
4 2 1 1
LLDD
6 3 3 1
RLRRRL
5 6 3 3
RUURD
7 5 3 4
RRDLUUU
7 123456789999 3 2
ULULURD
```


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Dyn-scripted Robot (Hard Version)
time_limit_ms: 3000
memory_limit_mb: 256
Description: This is the hard version of the problem. The only difference is that in this version $k \le 10^{12}$. You can make hacks only if both versions of the problem are solved.

Given a $w \times h$ rectangle on the $Oxy$ plane, with points $(0, 0)$ at the bottom-left and $(w, h)$ at the top-right of the rectangle.

You also have a robot initially at point $(0, 0)$ and a script $s$ of $n$ characters. Each character is either L, R, U, or D, which tells the robot to move left, right, up, or down respectively.

The robot can only move inside the rectangle; otherwise, it will change the script $s$ as follows:

  * If it tries to move outside a vertical border, it changes all L characters to R's (and vice versa, all R's to L's).    * If it tries to move outside a horizontal border, it changes all U characters to D's (and vice versa, all D's to U's).

Then, it will execute the changed script starting from the character which it couldn't execute.

![](CDN_BASE_URL/ff5ae9758c965c2d8398c936e9581dab) An example of the robot's movement process, $s = \texttt{"ULULURD"}$

The script $s$ will be executed for $k$ times continuously. All changes to the string $s$ will be retained even when it is repeated. During this process, how many times will the robot move to the point $(0, 0)$ in total? Note that the initial position does NOT count.

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 four integers $n$, $k$, $w$, and $h$ ($1 \le n, w, h \le 10^6$; $1 \le k \le 10^{12}$).

The second line contains a single string $s$ of size $n$ ($s_i \in \\{\texttt{L}, \texttt{R}, \texttt{U}, \texttt{D}\\}$) — the script to be executed.

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^6$.

Output: For each test case, print a single integer — the number of times the robot reaches $(0, 0)$ when executing script $s$ for $k$ times continuously.

Examples:
input:
6
2 4 2 2
UR
4 2 1 1
LLDD
6 3 3 1
RLRRRL
5 6 3 3
RUURD
7 5 3 4
RRDLUUU
7 123456789999 3 2
ULULURD
output:
1
4
3
1
1
41152263332

Note: In the first test case, the robot only moves up and right for the first two executions. After that, it occupies the position $(2, 2)$. For the next two executions, it moves down and left and finishes at $(0, 0)$. So the answer is $1$.

In the second test case, each time executing the script the robot visits the origin twice. And since $k=2$, it visits the origin $2 \cdot 2 = 4$ times overall.

![](CDN_BASE_URL/ea799abf84f8a212d5a0d782be4d5e9c)

In the third test case, the visualization is shown as below:

![](CDN_BASE_URL/c6a5be14982b3d57a5103783598d4683)

Buggy Code:
#include "bits/stdc++.h"

using namespace std;

#define ar array
typedef long long ll;
//~ #define int ll

template<class T> bool umin(T& a, const T b) { if(a > b) { a = b; return true; } return false; }
template<class T> bool umax(T& a, const T b) { if(a < b) { a = b; return true; } return false; }

const int MAXN = 2e5 + 5;

int phi[MAXN];
bool isPrime[MAXN];

void solve(){
	int n, w, h;
	ll k;

	cin >> n >> k >> w >> h;

	string s; cin >> s;

	vector<int> x_(n), y_(n);

	int ch[4][2] = {
		{0, -1},
		{0, 1},
		{-1, 0},
		{1, 0}
	};

	auto get = [&](char c){
		if(c == 'D') return 0;
		if(c == 'U') return 1;
		if(c == 'L') return 2;
		if(c == 'R') return 3;
		return 0;
	};

	int modX = 2 * w;
	int modY = 2 * h;

	for(int i=0;i<n;i++){
		if(i) x_[i] = x_[i - 1], y_[i] = y_[i - 1];

		int t = get(s[i]);
		x_[i] = (x_[i] + ch[t][0] + modX) % modX;
		y_[i] = (y_[i] + ch[t][1] + modY) % modY;
	}

	int X = x_[n - 1], Y = y_[n - 1];
	ll res = 0;

	auto bp = [&](int a, int b, int mod){
		int c = 1;
		while(b){
			if(b & 1) c = c * 1ll * a % mod;
			a = a * 1ll * a % mod;
			b >>= 1;
		}

		return c;
	};

	int modX_ = modX / gcd(modX, X);
	int modY_ = modY / gcd(modY, Y);
	ll L = lcm(modX_, modY_);

	auto inv = [&](int a, int mod){
		return bp(a, phi[mod] - 1, mod);
	};

	auto linear_mod = [&](int a, int b, int mod){
		// i * a = b (mod)
		// return b * a ^ {-1} (mod)

		int g = gcd(a, mod);
		if(b % g) return -1ll;

		a /= g, b /= g, mod /= g;

		if(mod == 1) return 0ll;
		return b * 1ll * inv(a, mod) % mod;
	};

	//~ cout<<"here"<<endl;

	for(int j=0;j<n;j++){
		auto [x, y] = (ar<int, 2>){x_[j], y_[j]};

		if(x) x = modX - x;
		if(y) y = modY - y;

		int ax = linear_mod(X, x, modX);
		int ay = linear_mod(Y, y, modY);

		if(ax == -1 || ay == -1) continue;

		// i = z * modX_ + ax
		// z * modX_ = ay - ax (modY_)
		int ay_ax = (ay - ax) % modY_;
		if(ay_ax < 0) ay_ax += modY_;

		int z = linear_mod(modX_, ay_ax, modY_);
		if(z == -1) continue;

		// z * modX_ = ay - ax (modY_)
		// i < k
		// z * modX_ + ax < k

		// k_ = (k - ax) / modX_
		// z < k_
		// (z + modY_) < k_
		// (z + modY_ * 2) < k_
		// x < (k_ - z) / modY_

		if(k < ax) continue;

		//~ z
		//~ z + L < k - ax - z
		//~ z + 2 * L < k - ax - z

		res += (k - ax - z + L - 1) / L;
	}

	cout<<res<<"\n";
}

signed main(){
	ios::sync_with_stdio(0); cin.tie(0);

	auto phiCalc = [&](int n){
		//~ vector<int> phi(n + 1);
		// vector<int> isPrime(n + 1, 1);
		// isPrime is notPrime
		vector<int> primes;

		for (int i = 2; i < n; i++) {
            if (!isPrime[i]) {
                phi[i] = i - 1;
                primes.push_back(i);
            }

            for (int j : primes) {
                if (i * j >= n)
                    break;
                isPrime[i * j] = true;
                if (i % j == 0) {
                    phi[i * j] = phi[i] * j;
                    break;
                } else {
                    phi[i * j] = phi[i] * (j - 1);
                }
            }
        }
		//~ return phi;
	};

	phiCalc(MAXN);

	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:
To generate a challenging test input that exposes the bug in the provided code, we need to focus on edge cases and scenarios that can cause the code to fail. Here are the steps to consider:

1. **Edge Cases for the Rectangle Size**:
   - Very small rectangle (e.g., \(1 \times 1\)).
   - Rectangle with one dimension being 1 (e.g., \(1 \times 10\) or \(10 \times 1\)).

2. **Edge Cases for the Script**:
   - Scripts that cause the robot to move outside the rectangle immediately.
   - Scripts that cause the robot to move in a pattern that repeatedly visits the origin.
   - Scripts that are very long and repetitive.

3. **Edge Cases for the Number of Executions**:
   - Large \(k\) values to test the performance and correctness of the code.
   - Small \(k\) values to test basic correctness.

4. **Combination of the Above**:
   - Combine small rectangle sizes with scripts that cause frequent changes to the script.
   - Combine large \(k\) values with scripts that cause the robot to move in complex patterns.

Given these considerations, let's create a test input that combines a small rectangle size with a script that causes the robot to move outside the rectangle immediately and repeatedly visit the origin.

### Test Input
```plaintext
3
2 1000000000000 1 1
LL
4 1000000000000 1 1
LLDD
6 1000000000000 1 1
LRLRLL
```

### Explanation
1. **Test Case 1**:
   - \(n = 2\), \(k = 10^{12}\), \(w = 1\), \(h = 1\)
   - Script: `LL`
   - The robot will try to move left twice, which will cause it to change `L` to `R` and vice versa. Since the rectangle is \(1 \times 1\), the robot will stay at the origin and not move.

2. **Test Case 2**:
   - \(n = 4\), \(k = 10^{12}\), \(w = 1\), \(h = 1\)
   - Script: `LLDD`
   - The robot will try to move left twice and down twice, which will cause it to change `L` to `R` and `D` to `U`. Since the rectangle is \(1 \times 1\), the robot will stay at the origin and not move.

3. **Test Case 3**:
   - \(n = 6\), \(k = 10^{12}\), \(w = 1\), \(h = 1\)
   - Script: `LRLRLL`
   - The robot will try to move in a pattern that causes frequent changes to the script. Since the rectangle is \(1 \times 1\), the robot will stay at the origin and not move.

This test input is designed to expose potential issues in the code, especially in handling very large \(k\) values and small rectangle sizes.