**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Go Learn! (Easy Version)
time_limit_ms: 5000
memory_limit_mb: 256
Description: The differences between the easy and hard versions are the constraints on $n$ and the sum of $n$. In this version, $n \leq 3000$ and the sum of $n$ does not exceed $10^4$. You can only make hacks if both versions are solved.

Well, well, well, let's see how Bessie is managing her finances. She seems to be in the trenches! Fortunately, she is applying for a job at Moogle to resolve this issue. Moogle interviews require intensive knowledge of obscure algorithms and complex data structures, but Bessie received a tip-off from an LGM on exactly what she has to go learn.

Bessie wrote the following code to binary search for a certain element $k$ in a possibly unsorted array $[a_1, a_2,\ldots,a_n]$ with $n$ elements.

              let l = 1     let h = n          while l < h:       let m = floor((l + h) / 2)            if a[m] < k:         l = m + 1       else:         h = m          return l

Bessie submitted her code to Farmer John's problem with $m$ ($1 \leq m \leq n$) tests. The $i$-th test is of the form $(x_i, k_i)$ ($1 \leq x, k \leq n$). It is guaranteed all the $x_i$ are distinct and all the $k_i$ are distinct.

Test $i$ is correct if the following hold:

  1. The $x_i$-th element in the array is $k_i$.    2. If Bessie calls the binary search as shown in the above code for $k_i$, it will return $x_i$.

It might not be possible for all $m$ tests to be correct on the same array, so Farmer John will remove some of them so Bessie can AC. Let $r$ be the minimum of tests removed so that there exists an array $[a_1, a_2,\ldots,a_n]$ with $1 \leq a_i \leq n$ so that all remaining tests are correct.

In addition to finding $r$, Farmer John wants you to count the number of arrays $[a_1, a_2,\ldots,a_n]$ with $1 \leq a_i \leq n$ such that there exists a way to remove exactly $r$ tests so that all the remaining tests are correct. Since this number may be very large, please find it modulo $998\,244\,353$.

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 two integers $n$ and $m$ ($1 \leq m \leq n \leq 3000$) denoting the number of the array and the number of tests.

The following $m$ lines each contain two integers, describing the tests. The $i$-th line contains two integers $x_i$ and $k_i$ ($1 \leq x_i, k_i \leq n$) denoting the index and value of the test. It is guaranteed all $x_i$ are distinct and all $k_i$ are distinct.

It is guaranteed the sum of $n$ across all test cases does not exceed $10^4$.

Output: For each test case, output two integers, $r$ — the minimum of tests removed so that there exists an array so that all remaining tests are correct, and the number of arrays such that it is possible to remove $r$ tests to make all remaining tests correct modulo $998\,244\,353$.

Examples:
input:
2
5 4
1 1
2 2
4 3
5 4
5 4
5 4
2 5
1 2
3 3
output:
0 1
1 3

input:
2
6 6
1 3
2 5
3 1
4 2
5 4
6 6
30 8
19 22
6 12
12 1
28 27
3 4
14 25
29 14
11 15
output:
3 78
3 839271911

Note: Consider the first example.

In the first test case, the array $[1,2,2,3,4]$ satisfies all $m$ tests, so the minimum number of tests Bessie has to remove is $0$. Note that this is also the only array that satisfies all $m$ tests.

In the second test case, the minimum number of tests Bessie has to remove is $1$. The only test Bessie can remove is $(2,5)$. If Bessie removes test $(2,5)$, then the arrays satisfying the remaining $m-1$ tests are $[2,2,3,1,4]$, $[2,2,3,2,4]$, $[2,2,3,3,4]$.

Buggy Code:
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
typedef long long ll;
const ll mod=998244353;
const int N=3005;
int n,m;
ll guy[N];
int d[N];
ll dp[N];
ll ways[N];

ll pn[N][N];
int filled[N];
void dfs(int l,int r,int frog){
	if(l==r){
		d[l]+=frog;//d[l] = number of elements that is forced < guy[l] in [1..l-1]
		return;
	}
	int mid=(l+r)/2;
	dfs(l,mid,frog);
	dfs(mid+1,r,frog+1);
}
void aespa(int l,int r){
	if(l==r) return;
	int mid=(l+r)/2;
	aespa(l,mid);
	for(int i=l; i<=mid ;i++){
		for(int j=mid+1; j<=r ;j++){
			if(guy[i]==0 || guy[j]==0 || guy[i]>guy[j] || dp[i]==0) continue;
			//cout << "trans " << i << ' ' << j << ' ' << ways[i] << ' ' << guy[i] << endl;
			int newi=(j-filled[i]-2+(i==mid));
			//cout << mid << ' ' << filled[i] << endl;
			int force=d[j]-d[l]-1;
			ll middle=guy[j]-guy[i];
			if(i==mid)  middle=1;
			//cout << "haha " << newi << ' ' << force << ' ' << middle << endl;
			//and multiply number of ways to pick [mid]

			if(dp[j]<dp[i]+1){
				dp[j]=dp[i]+1;
				ways[j]=0;
			}
			if(dp[j]==dp[i]+1){
				ways[j]=(ways[j]+ways[i]*pn[n][newi-force]%mod*pn[guy[j]-1][force]%mod*middle)%mod;
			}
			//cout << "fin " << ways[j] << endl;
		}
	}
	aespa(mid+1,r);
	for(int i=l; i<mid ;i++){
		filled[i]++;
		if(guy[i]!=0){
			ways[i]=ways[i]*(n-guy[i]+1)%mod;
		}
	}
}
void solve(){
	cin >> n >> m;
	pn[0][0]=1;
	for(int i=1; i<=n ;i++){
		guy[i]=0;
		d[i]=0;
		dp[i]=0;
		ways[i]=0;
		filled[i]=i;
		pn[i][0]=1;
		for(int j=1; j<=n ;j++){
			pn[i][j]=pn[i][j-1]*i%mod;
		}
	}
	ways[0]=1;
	for(int i=1; i<=m ;i++){
		int x,k;cin >> x >> k;
		guy[x]=k;
	}
	dfs(1,n,0);
	for(int i=1; i<=n ;i++){
		if(guy[i]==0) continue;
		if(guy[i]==1 && d[i]!=0){
			dp[i]=0;
			ways[i]=0;
			continue;
		}
		dp[i]=1;
		ways[i]=pn[guy[i]-1][d[i]]*pn[n][i-d[i]-1]%mod;
	}
	aespa(1,n);
	ll mx=1,w=0;
	for(int i=1; i<=n ;i++){
		if(dp[i]>mx){
			mx=dp[i];w=0;
		}
		if(dp[i]==mx){
			w=(w+ways[i]*pn[n][n-filled[i]])%mod;
		}
		//cout << "haha " << dp[i] << ' ' << ways[i] << endl;
	}
	cout << m-mx << ' ' << w << '\n';
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);
	int t;cin >> t;
	while(t--) solve();
}

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

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

Think step by step.

Response:
```plaintext
1
5 5
1 3
2 1
3 5
4 2
5 4
```


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Go Learn! (Easy Version)
time_limit_ms: 5000
memory_limit_mb: 256
Description: The differences between the easy and hard versions are the constraints on $n$ and the sum of $n$. In this version, $n \leq 3000$ and the sum of $n$ does not exceed $10^4$. You can only make hacks if both versions are solved.

Well, well, well, let's see how Bessie is managing her finances. She seems to be in the trenches! Fortunately, she is applying for a job at Moogle to resolve this issue. Moogle interviews require intensive knowledge of obscure algorithms and complex data structures, but Bessie received a tip-off from an LGM on exactly what she has to go learn.

Bessie wrote the following code to binary search for a certain element $k$ in a possibly unsorted array $[a_1, a_2,\ldots,a_n]$ with $n$ elements.

              let l = 1     let h = n          while l < h:       let m = floor((l + h) / 2)            if a[m] < k:         l = m + 1       else:         h = m          return l

Bessie submitted her code to Farmer John's problem with $m$ ($1 \leq m \leq n$) tests. The $i$-th test is of the form $(x_i, k_i)$ ($1 \leq x, k \leq n$). It is guaranteed all the $x_i$ are distinct and all the $k_i$ are distinct.

Test $i$ is correct if the following hold:

  1. The $x_i$-th element in the array is $k_i$.    2. If Bessie calls the binary search as shown in the above code for $k_i$, it will return $x_i$.

It might not be possible for all $m$ tests to be correct on the same array, so Farmer John will remove some of them so Bessie can AC. Let $r$ be the minimum of tests removed so that there exists an array $[a_1, a_2,\ldots,a_n]$ with $1 \leq a_i \leq n$ so that all remaining tests are correct.

In addition to finding $r$, Farmer John wants you to count the number of arrays $[a_1, a_2,\ldots,a_n]$ with $1 \leq a_i \leq n$ such that there exists a way to remove exactly $r$ tests so that all the remaining tests are correct. Since this number may be very large, please find it modulo $998\,244\,353$.

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 two integers $n$ and $m$ ($1 \leq m \leq n \leq 3000$) denoting the number of the array and the number of tests.

The following $m$ lines each contain two integers, describing the tests. The $i$-th line contains two integers $x_i$ and $k_i$ ($1 \leq x_i, k_i \leq n$) denoting the index and value of the test. It is guaranteed all $x_i$ are distinct and all $k_i$ are distinct.

It is guaranteed the sum of $n$ across all test cases does not exceed $10^4$.

Output: For each test case, output two integers, $r$ — the minimum of tests removed so that there exists an array so that all remaining tests are correct, and the number of arrays such that it is possible to remove $r$ tests to make all remaining tests correct modulo $998\,244\,353$.

Examples:
input:
2
5 4
1 1
2 2
4 3
5 4
5 4
5 4
2 5
1 2
3 3
output:
0 1
1 3

input:
2
6 6
1 3
2 5
3 1
4 2
5 4
6 6
30 8
19 22
6 12
12 1
28 27
3 4
14 25
29 14
11 15
output:
3 78
3 839271911

Note: Consider the first example.

In the first test case, the array $[1,2,2,3,4]$ satisfies all $m$ tests, so the minimum number of tests Bessie has to remove is $0$. Note that this is also the only array that satisfies all $m$ tests.

In the second test case, the minimum number of tests Bessie has to remove is $1$. The only test Bessie can remove is $(2,5)$. If Bessie removes test $(2,5)$, then the arrays satisfying the remaining $m-1$ tests are $[2,2,3,1,4]$, $[2,2,3,2,4]$, $[2,2,3,3,4]$.

Buggy Code:
from collections import defaultdict
from math import prod
P = 998244353
def solve():
    n, m = map(int, input().split())
    a = [list(map(int, input().split())) for _ in range(m)]
    def bsearch(x):
        l, h = 1, n
        while l < h:
            m = l + h >> 1
            yield m
            if m < x: l = m + 1
            else: h = m

    a.append([0, 0])
    a.append([n+1, n+1])
    a.sort()
    L = [1] * len(a)
    W = [0] * len(a)
    W[0] = 1
    for i in range(1, len(a)):
        x2, k2 = a[i]
        l = 0
        for j in range(i):
            x1, k1 = a[j]
            if k1 < k2 and W[j]:
                l = max(l, L[j])
        L[i] = l + 1
        for j in range(i):
            x1, k1 = a[j]
            q = defaultdict(int)
            if k1 < k2 and L[j] == l:
                for t in bsearch(x1):
                    if x1 < t < x2:
                        q[t] += max(0, k1 - 1)
                for t in bsearch(x2):
                    if x1 < t < x2:
                        q[t] += n - k2 + 1
                z = W[j] * pow(n, x2 - x1 - len(q) - 1, P)
                for v in q.values():
                    z = z * (n - v) % P
                W[i] = (W[i] + z) % P
    print(m - L[-1] + 2, W[-1])

for _ in range(int(input())):
    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
2
5 4
1 1
2 2
4 3
5 4
5 4
5 4
2 5
1 2
3 3
```


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Go Learn! (Easy Version)
time_limit_ms: 5000
memory_limit_mb: 256
Description: The differences between the easy and hard versions are the constraints on $n$ and the sum of $n$. In this version, $n \leq 3000$ and the sum of $n$ does not exceed $10^4$. You can only make hacks if both versions are solved.

Well, well, well, let's see how Bessie is managing her finances. She seems to be in the trenches! Fortunately, she is applying for a job at Moogle to resolve this issue. Moogle interviews require intensive knowledge of obscure algorithms and complex data structures, but Bessie received a tip-off from an LGM on exactly what she has to go learn.

Bessie wrote the following code to binary search for a certain element $k$ in a possibly unsorted array $[a_1, a_2,\ldots,a_n]$ with $n$ elements.

              let l = 1     let h = n          while l < h:       let m = floor((l + h) / 2)            if a[m] < k:         l = m + 1       else:         h = m          return l

Bessie submitted her code to Farmer John's problem with $m$ ($1 \leq m \leq n$) tests. The $i$-th test is of the form $(x_i, k_i)$ ($1 \leq x, k \leq n$). It is guaranteed all the $x_i$ are distinct and all the $k_i$ are distinct.

Test $i$ is correct if the following hold:

  1. The $x_i$-th element in the array is $k_i$.    2. If Bessie calls the binary search as shown in the above code for $k_i$, it will return $x_i$.

It might not be possible for all $m$ tests to be correct on the same array, so Farmer John will remove some of them so Bessie can AC. Let $r$ be the minimum of tests removed so that there exists an array $[a_1, a_2,\ldots,a_n]$ with $1 \leq a_i \leq n$ so that all remaining tests are correct.

In addition to finding $r$, Farmer John wants you to count the number of arrays $[a_1, a_2,\ldots,a_n]$ with $1 \leq a_i \leq n$ such that there exists a way to remove exactly $r$ tests so that all the remaining tests are correct. Since this number may be very large, please find it modulo $998\,244\,353$.

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 two integers $n$ and $m$ ($1 \leq m \leq n \leq 3000$) denoting the number of the array and the number of tests.

The following $m$ lines each contain two integers, describing the tests. The $i$-th line contains two integers $x_i$ and $k_i$ ($1 \leq x_i, k_i \leq n$) denoting the index and value of the test. It is guaranteed all $x_i$ are distinct and all $k_i$ are distinct.

It is guaranteed the sum of $n$ across all test cases does not exceed $10^4$.

Output: For each test case, output two integers, $r$ — the minimum of tests removed so that there exists an array so that all remaining tests are correct, and the number of arrays such that it is possible to remove $r$ tests to make all remaining tests correct modulo $998\,244\,353$.

Examples:
input:
2
5 4
1 1
2 2
4 3
5 4
5 4
5 4
2 5
1 2
3 3
output:
0 1
1 3

input:
2
6 6
1 3
2 5
3 1
4 2
5 4
6 6
30 8
19 22
6 12
12 1
28 27
3 4
14 25
29 14
11 15
output:
3 78
3 839271911

Note: Consider the first example.

In the first test case, the array $[1,2,2,3,4]$ satisfies all $m$ tests, so the minimum number of tests Bessie has to remove is $0$. Note that this is also the only array that satisfies all $m$ tests.

In the second test case, the minimum number of tests Bessie has to remove is $1$. The only test Bessie can remove is $(2,5)$. If Bessie removes test $(2,5)$, then the arrays satisfying the remaining $m-1$ tests are $[2,2,3,1,4]$, $[2,2,3,2,4]$, $[2,2,3,3,4]$.

Buggy Code:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,del##i##verme=int(n);i<del##i##verme;++i)
#define rep1(i,n) for(int i=1,parano##i##a=int(n);i<=parano##i##a;++i)
#define per(i,n) for(int i=int(n)-1;i>=0;--i)
#define per1(i,n) for(int i=int(n);i>=1;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define y0 LingLuo
#define y1 VividCycle
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldb;
using namespace std;
const ll mod1=998244353;
unsigned time_related_rand()
{
	return unsigned(std::chrono::steady_clock::now().time_since_epoch().count());
}
struct query{
	int x,k;
};
bool operator<(const query&u,const query&v)
{
	return u.x<v.x;
}
int l[6005],r[6005],p[6005];
int t,n,m;
query q[3005];
int lis[3005];
int dep[3005];
ll dp[3005];
ll pw[3005];
int root;
int dfs(int L,int R,int d)
{
	if(L==R)
	{
		dep[L+n]=d;
		return L+n;
	}
	int mid=(L+R)>>1;
	dep[mid]=d;
	l[mid]=dfs(L,mid,d+1);
	r[mid]=dfs(mid+1,R,d+1);
	p[l[mid]]=p[r[mid]]=mid;
	return mid;
}
ll val(int x,int y,int f,int g)// f~g
{
	ll ret=1;int cnt=y-x-1;
	int cx=x+n,cy=y+n;
	while(cx!=root&&cy!=root)
	{
		if(p[cx]==p[cy])
		{
			cx=p[cx];cy=p[cy];
			if(x<cx&&cy<y)
			{
				ret=ret*(g-f+1)%mod1;
				--cnt;
			}
		}
		else
		{
			if(dep[cx]>dep[cy])
			{
				cx=p[cx];
				if(x<cx&&cx<y)
				{
					ret=ret*(n-f+1)%mod1;
					--cnt;
				}
			}
			else
			{
				cy=p[cy];
				if(x<cy&&cy<y)
				{
					ret=ret*g%mod1;
					--cnt;
				}
			}
		}
	}
	return ret*pw[cnt]%mod1;
}
ll bef(int y,int g)
{
	if(y==1) return 1;
	ll ret=1;int cnt=y-1;
	int cur=y+n;
	while(cur!=root)
	{
		cur=p[cur];
		if(cur<y)
		{
			ret=ret*g%mod1;
			--cnt;
		}
	}
	return ret*pw[cnt]%mod1;
}
ll aft(int x,int f)
{
	if(x==n) return 1;
	ll ret=1;int cnt=n-x;
	int cur=x+n;
	while(cur!=root)
	{
		cur=p[cur];
		if(cur>x)
		{
			ret=ret*(n-f+1)%mod1;
			--cnt;
		}
	}
	return ret*pw[cnt]%mod1;
}
ll x[3005],y[3005];
ll qaq[3005];
void Q()
{
	cin>>n>>m;
	rep1(i,m)
	{
		cin>>q[i].x>>q[i].k;
	}
	if(n==1)
	{
		cout<<"0 1\n";
		return ;
	}
	sort(q+1,q+m+1);
	root=dfs(1,n,0);
//	return ;
	pw[0]=1;rep1(i,n)pw[i]=pw[i-1]*n%mod1;
	rep1(i,m)
	{
		x[i]=bef(q[i].x,q[i].k-1);
		y[i]=aft(q[i].x,q[i].k);
	}
	int qq=0;
	rep1(i,m)
	{
		if(x[i])
		lis[i]=1;
		else
		lis[i]=-1145141919;
		for(int j=1;j<i;++j) if(lis[j]!=-1145141919&&q[j].k<q[i].k&&(qaq[j]=val(q[j].x,q[i].x,q[j].k,q[i].k-1)))
		{
			lis[i]=max(lis[i],lis[j]+1);
		}
		if(lis[i]==1)
		{
			dp[i]=x[i];
		}
		else
		{
			dp[i]=0;
			for(int j=1;j<i;++j) if(q[j].k<q[i].k&&lis[i]==lis[j]+1&&qaq[j])
			{
				dp[i]=(dp[i]+dp[j]*qaq[j])%mod1;
			}
		}
		if(y[i]) qq=max(qq,lis[i]);
	//	cout<<i<<";"<<lis[i]<<" "<<dp[i]<<endl;
	}
	cout<<m-qq<<" ";
	ll answer=0;
	rep1(i,m) if(lis[i]==qq)
	{
		answer=(answer+dp[i]*y[i])%mod1;
	//	cout<<i<<" "<<aft(i,q[i].k)<<"!!"<<endl;
	}
	if(qq==0)
	{
		answer=1;rep1(i,n)answer=answer*n%mod1;
	}
	cout<<answer<<"\n";
}
int main()
{
	#ifndef DEBUG
	ios_base::sync_with_stdio(false);cin.tie(0);
	#endif
	cin>>t;while(t--)Q();return 0;
}
/* things to check
1.  int overflow or long long memory need
2.  recursion/array/binary search/dp/loop bounds
3.  precision
4.  special cases(n=1,bounds)
5.  delete debug statements
6.  initialize(especially multi-tests)
7.  = or == , n or m ,++ or -- , i or j , > or >= , < or <=
8.  keep it simple and stupid
9.  do not delete, use // instead
10. operator priority
11. is there anything extra to output?
12. ...
*/

/* something to think about
1. greedy? dp? searching? dp with matrix/ segment tree? binary search?
2. If contains "not", why not ?????? or few affect?
*/

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

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

Think step by step.

Response:
To expose the bug in the given code, we need to focus on scenarios that can cause the binary search logic to fail, particularly in handling unsorted arrays and edge cases. Here are the steps to generate a challenging test input:

1. **Edge Cases for Binary Search**:
   - Ensure that the array is not sorted, as the binary search assumes the array is sorted.
   - Include values that could cause the binary search to return incorrect indices.

2. **Constraints and Special Cases**:
   - Use the smallest possible values for `n` and `m` to ensure the test case is small-scale.
   - Ensure that the `x` and `k` values are distinct and within the constraints.

3. **Test Case Construction**:
   - Create an array where the binary search will return incorrect results.
   - Ensure that the tests are such that the binary search logic will fail to find the correct indices.

Given these considerations, here is a small-scale test input that should expose the bug:

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

### Explanation:
- **Test Case 1**:
  - **Array Length (n)**: 5
  - **Number of Tests (m)**: 3
  - **Tests**:
    - (1, 3): The first element should be 3.
    - (2, 1): The second element should be 1.
    - (5, 2): The fifth element should be 2.

### Expected Behavior:
- The binary search in the given code will fail because the array is not sorted, and the binary search assumes a sorted array.
- The correct array that satisfies all tests would be `[3, 1, x, y, 2]`, where `x` and `y` can be any values that do not conflict with the tests.

### Why This Test Case is Challenging:
- The array is not sorted, which will cause the binary search to return incorrect indices.
- The tests are designed to ensure that the binary search logic will fail to find the correct indices, exposing the bug in the code.

This test input should help in identifying the issues with the binary search logic in the given code.


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Go Learn! (Easy Version)
time_limit_ms: 5000
memory_limit_mb: 256
Description: The differences between the easy and hard versions are the constraints on $n$ and the sum of $n$. In this version, $n \leq 3000$ and the sum of $n$ does not exceed $10^4$. You can only make hacks if both versions are solved.

Well, well, well, let's see how Bessie is managing her finances. She seems to be in the trenches! Fortunately, she is applying for a job at Moogle to resolve this issue. Moogle interviews require intensive knowledge of obscure algorithms and complex data structures, but Bessie received a tip-off from an LGM on exactly what she has to go learn.

Bessie wrote the following code to binary search for a certain element $k$ in a possibly unsorted array $[a_1, a_2,\ldots,a_n]$ with $n$ elements.

              let l = 1     let h = n          while l < h:       let m = floor((l + h) / 2)            if a[m] < k:         l = m + 1       else:         h = m          return l

Bessie submitted her code to Farmer John's problem with $m$ ($1 \leq m \leq n$) tests. The $i$-th test is of the form $(x_i, k_i)$ ($1 \leq x, k \leq n$). It is guaranteed all the $x_i$ are distinct and all the $k_i$ are distinct.

Test $i$ is correct if the following hold:

  1. The $x_i$-th element in the array is $k_i$.    2. If Bessie calls the binary search as shown in the above code for $k_i$, it will return $x_i$.

It might not be possible for all $m$ tests to be correct on the same array, so Farmer John will remove some of them so Bessie can AC. Let $r$ be the minimum of tests removed so that there exists an array $[a_1, a_2,\ldots,a_n]$ with $1 \leq a_i \leq n$ so that all remaining tests are correct.

In addition to finding $r$, Farmer John wants you to count the number of arrays $[a_1, a_2,\ldots,a_n]$ with $1 \leq a_i \leq n$ such that there exists a way to remove exactly $r$ tests so that all the remaining tests are correct. Since this number may be very large, please find it modulo $998\,244\,353$.

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 two integers $n$ and $m$ ($1 \leq m \leq n \leq 3000$) denoting the number of the array and the number of tests.

The following $m$ lines each contain two integers, describing the tests. The $i$-th line contains two integers $x_i$ and $k_i$ ($1 \leq x_i, k_i \leq n$) denoting the index and value of the test. It is guaranteed all $x_i$ are distinct and all $k_i$ are distinct.

It is guaranteed the sum of $n$ across all test cases does not exceed $10^4$.

Output: For each test case, output two integers, $r$ — the minimum of tests removed so that there exists an array so that all remaining tests are correct, and the number of arrays such that it is possible to remove $r$ tests to make all remaining tests correct modulo $998\,244\,353$.

Examples:
input:
2
5 4
1 1
2 2
4 3
5 4
5 4
5 4
2 5
1 2
3 3
output:
0 1
1 3

input:
2
6 6
1 3
2 5
3 1
4 2
5 4
6 6
30 8
19 22
6 12
12 1
28 27
3 4
14 25
29 14
11 15
output:
3 78
3 839271911

Note: Consider the first example.

In the first test case, the array $[1,2,2,3,4]$ satisfies all $m$ tests, so the minimum number of tests Bessie has to remove is $0$. Note that this is also the only array that satisfies all $m$ tests.

In the second test case, the minimum number of tests Bessie has to remove is $1$. The only test Bessie can remove is $(2,5)$. If Bessie removes test $(2,5)$, then the arrays satisfying the remaining $m-1$ tests are $[2,2,3,1,4]$, $[2,2,3,2,4]$, $[2,2,3,3,4]$.

Buggy Code:
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <random>
#include <chrono>

using namespace std;

#define _int64 long long
#define mo 998244353

map<pair<int,int>,int> ind;
int nn;
map<pair<int,int>,pair<int,_int64> > d[10000][2];
int n,m;
_int64 pown[3100];

void upd(pair<int,_int64>& ans,pair<int,_int64>& tmp)
{
	if (tmp.first>ans.first) ans=tmp;
	else if (tmp.first==ans.first)
	{
		ans.second+=tmp.second;
		ans.second%=mo;
	}
}

pair<int,_int64> doit(int ll,int rr,int bit,int vl,int vr,vector<pair<int,int> >& aa)
{
	int id,i,j,prev,cnt,mid;
	vector<pair<int,int> > v;
	vector<pair<int,int> > a1,a2;
	pair<int,_int64> v1,v0;
	pair<int,_int64> v2;
	if (aa.size()==0)
	{
		//cerr<<"ll,rr,vl,vr0:"<<ll<<" "<<rr<<" "<<vl<<" "<<vr<<endl;
		if (rr==n) return make_pair(0,pown[rr-ll+1]);
		else return make_pair(0,pown[rr-ll]);
	}
	if (ll==rr)
	{
		//cerr<<"ll,rr1:"<<ll<<" "<<rr<<" "<<aa.size()<<endl;
		//for (i=0;i<aa.size();i++)
		//	cerr<<"aa:"<<aa[i].first<<" "<<aa[i].second<<endl;
		if (bit==1) return make_pair(1,1);
		else return make_pair(0,1);
	}
	if (ind.find(make_pair(ll,rr))==ind.end())
	{
		ind[make_pair(ll,rr)]=nn;
		d[nn][0].clear();
		d[nn][1].clear();
		nn++;
	}
	id=ind[make_pair(ll,rr)];
	if (d[id][bit].find(make_pair(vl,vr))!=d[id][bit].end()) return d[id][bit][make_pair(vl,vr)];
	mid=(ll+rr)/2;
	v.clear();
	for (i=0;i<aa.size();i++)
		v.push_back(make_pair(aa[i].second,aa[i].first));
	sort(v.begin(),v.end());
	v.push_back(make_pair(n+1,1));
	prev=1;
	pair<int,_int64> ans,tmp,tmp1;
	ans=make_pair(-1,0);
	for (i=0;i<v.size();i++)
	{
		//cerr<<"i,v,prev:"<<i<<" "<<v[i]<<" "<<prev<<endl;
		cnt=v[i].first-prev;
		if (cnt==0) continue;
		a1.clear();
		a2.clear();
		for (j=0;j<aa.size();j++)
		{
			if ((aa[j].first<=mid)&&(aa[j].second<=v[i].first-1)) a1.push_back(aa[j]);
			if ((aa[j].first>mid)&&(aa[j].second>v[i].first-1)) a2.push_back(aa[j]);
		}
		v1=doit(ll,mid,0,vl,min(vr,v[i].first-1),a1);
		if ((i-1>=0)&&(v[i-1].second==mid))
		{
			v0=doit(ll,mid,1,vl,min(vr,v[i].first-1),a1);
			if (cnt-1==0) v1=v0;
			else
			{
				v1.second*=(cnt-1);
				v1.second%=mo;
				upd(v1,v0);
			}
		}
		else
		{
			v1.second*=cnt;
			v1.second%=mo;
		}
		//cerr<<"sz:"<<a1.size()<<" "<<a2.size()<<endl;
		v2=doit(mid+1,rr,bit,max(vl,v[i].first),vr,a2);
		tmp=make_pair(v1.first+v2.first,v1.second*v2.second%mo);
		upd(ans,tmp);
		//cerr<<"ll,rr,tmp.second:"<<ll<<" "<<rr<<" "<<vl<<" "<<vr<<" "<<tmp.first<<" "<<tmp.second<<" "<<cnt<<" "<<v[i].first<<" "<<prev<<endl;
		//cerr<<"tmp.second:"<<tmp.second<<endl;
		prev=v[i].first;
	}
	d[id][bit][make_pair(vl,vr)]=ans;
	//cerr<<"d:"<<ll<<" "<<rr<<" "<<vl<<" "<<vr<<" "<<ans.first<<" "<<ans.second<<" "<<aa.size()<<endl;
	return ans;
}

int main()
{
	int i,j,k,l,t,x,y,o,b1;
	scanf("%d",&t);
	vector<pair<int,int> > aa;
	for (l=0;l<t;l++)
	{
		scanf("%d%d",&n,&m);
		pown[0]=1;
		for (i=1;i<=n;i++)
			pown[i]=pown[i-1]*n%mo;
		aa.clear();
		for (i=0;i<m;i++)
		{
			scanf("%d%d",&x,&y);
			aa.push_back(make_pair(x,y));
		}
		ind.clear();
		nn=0;
		pair<int,_int64> ans=doit(1,n,1,1,n,aa);
		printf("%d %lld\n",m-ans.first,ans.second);
	}
}

**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 create a test input that exposes the bug in the given code, we need to focus on edge cases and scenarios that maximize the probability of failure. The code is supposed to handle binary search in a potentially unsorted array, and it needs to find the minimum number of tests to remove so that the remaining tests can be satisfied by some array.

### Key Points to Consider:
1. **Edge Cases:**
   - Arrays with very few elements.
   - Arrays with all elements being the same.
   - Arrays with elements in a specific order that might break the binary search logic.
2. **Constraints:**
   - \( n \leq 3000 \)
   - The sum of \( n \) across all test cases does not exceed \( 10^4 \)
   - \( 1 \leq m \leq n \)
   - All \( x_i \) and \( k_i \) are distinct.

### Test Input Generation:
Let's create a test case with a small \( n \) and \( m \) that might expose the bug in the binary search logic.

### Example Test Input:
```plaintext
2
5 4
1 1
2 2
4 3
5 4
5 4
5 4
2 5
1 2
3 3
```

### Explanation:
1. **First Test Case:**
   - \( n = 5 \)
   - \( m = 4 \)
   - Tests: \((1, 1)\), \((2, 2)\), \((4, 3)\), \((5, 4)\)
   - This test case is designed to check if the code can handle a small array where the elements are in a specific order that might break the binary search logic.

2. **Second Test Case:**
   - \( n = 5 \)
   - \( m = 4 \)
   - Tests: \((5, 4)\), \((2, 5)\), \((1, 2)\), \((3, 3)\)
   - This test case is designed to check if the code can handle a small array with a different order of elements and indices.

### Expected Output:
```plaintext
0 1
1 3
```

### Reasoning:
- **First Test Case:**
  - The array \([1, 2, 2, 3, 4]\) satisfies all tests, so the minimum number of tests to remove is 0.
  - There is only one such array.

- **Second Test Case:**
  - The minimum number of tests to remove is 1.
  - The possible arrays satisfying the remaining tests are \([2, 2, 3, 1, 4]\), \([2, 2, 3, 2, 4]\), \([2, 2, 3, 3, 4]\).

This test input should help expose any issues in the binary search logic and the way the code handles the constraints.


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Go Learn! (Easy Version)
time_limit_ms: 5000
memory_limit_mb: 256
Description: The differences between the easy and hard versions are the constraints on $n$ and the sum of $n$. In this version, $n \leq 3000$ and the sum of $n$ does not exceed $10^4$. You can only make hacks if both versions are solved.

Well, well, well, let's see how Bessie is managing her finances. She seems to be in the trenches! Fortunately, she is applying for a job at Moogle to resolve this issue. Moogle interviews require intensive knowledge of obscure algorithms and complex data structures, but Bessie received a tip-off from an LGM on exactly what she has to go learn.

Bessie wrote the following code to binary search for a certain element $k$ in a possibly unsorted array $[a_1, a_2,\ldots,a_n]$ with $n$ elements.

              let l = 1     let h = n          while l < h:       let m = floor((l + h) / 2)            if a[m] < k:         l = m + 1       else:         h = m          return l

Bessie submitted her code to Farmer John's problem with $m$ ($1 \leq m \leq n$) tests. The $i$-th test is of the form $(x_i, k_i)$ ($1 \leq x, k \leq n$). It is guaranteed all the $x_i$ are distinct and all the $k_i$ are distinct.

Test $i$ is correct if the following hold:

  1. The $x_i$-th element in the array is $k_i$.    2. If Bessie calls the binary search as shown in the above code for $k_i$, it will return $x_i$.

It might not be possible for all $m$ tests to be correct on the same array, so Farmer John will remove some of them so Bessie can AC. Let $r$ be the minimum of tests removed so that there exists an array $[a_1, a_2,\ldots,a_n]$ with $1 \leq a_i \leq n$ so that all remaining tests are correct.

In addition to finding $r$, Farmer John wants you to count the number of arrays $[a_1, a_2,\ldots,a_n]$ with $1 \leq a_i \leq n$ such that there exists a way to remove exactly $r$ tests so that all the remaining tests are correct. Since this number may be very large, please find it modulo $998\,244\,353$.

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 two integers $n$ and $m$ ($1 \leq m \leq n \leq 3000$) denoting the number of the array and the number of tests.

The following $m$ lines each contain two integers, describing the tests. The $i$-th line contains two integers $x_i$ and $k_i$ ($1 \leq x_i, k_i \leq n$) denoting the index and value of the test. It is guaranteed all $x_i$ are distinct and all $k_i$ are distinct.

It is guaranteed the sum of $n$ across all test cases does not exceed $10^4$.

Output: For each test case, output two integers, $r$ — the minimum of tests removed so that there exists an array so that all remaining tests are correct, and the number of arrays such that it is possible to remove $r$ tests to make all remaining tests correct modulo $998\,244\,353$.

Examples:
input:
2
5 4
1 1
2 2
4 3
5 4
5 4
5 4
2 5
1 2
3 3
output:
0 1
1 3

input:
2
6 6
1 3
2 5
3 1
4 2
5 4
6 6
30 8
19 22
6 12
12 1
28 27
3 4
14 25
29 14
11 15
output:
3 78
3 839271911

Note: Consider the first example.

In the first test case, the array $[1,2,2,3,4]$ satisfies all $m$ tests, so the minimum number of tests Bessie has to remove is $0$. Note that this is also the only array that satisfies all $m$ tests.

In the second test case, the minimum number of tests Bessie has to remove is $1$. The only test Bessie can remove is $(2,5)$. If Bessie removes test $(2,5)$, then the arrays satisfying the remaining $m-1$ tests are $[2,2,3,1,4]$, $[2,2,3,2,4]$, $[2,2,3,3,4]$.

Buggy Code:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 3e5;
const ll mod = 998244353;
ll n, m;
struct dpnode{
    ll nr, nr2;
}dp[N];
void add(dpnode &a, dpnode b){
    if(b.nr2 == 0)return;
    if(a.nr < b.nr){
        a = b;
    }else if(a.nr == b.nr){
        a.nr2 = (a.nr2 + b.nr2)%mod;
    }
}
ll fastexp(ll a, ll b){
    assert(b >= 0);
    ll r = 1;
    while(b){
        if(b&1)r = 1ll*r*a%mod;
        a = 1ll*a*a%mod;
        b/=2;
    }
    return r;
}
vector <ll> touch(ll x){
    vector <ll> p;
    ll l = 0, r = n - 1;
    while(l != r){
        ll mij = (l + r)/2;
        p.push_back(mij);
        if(x <= mij){
            r = mij;
        }else{
            l = mij + 1;
        }
    }
    return p;
}
struct ev{
    ll pos, t;
}v[N];
dpnode dp2[N], dp3[N];
ll v2[N];
void solve(){
    cin>>n>>m;
    for(ll i = 0;i < n;i++){
        dp[i] = {-mod, 0};
        dp2[i] = {-mod, 0};
        dp3[i] = {-mod, 0};
        v2[i] = 0;
    }
    for(ll i = 0;i < m;i++){
        ll x, p;
        cin>>p>>x;
        p--;
        v[i] = {p, x};
        v2[p] = x;
    }
    sort(v, v + m,[&](ev a, ev b){
         return a.t < b.t;
    });
    for(ll i = 0;i < m;i++){
        auto x = touch(v[i].pos);
        ll nr = fastexp(n, v[i].pos);
        for(auto j:x){
            if(j < v[i].pos){
                nr = 1ll*nr*fastexp(n, mod - 2)%mod*(v[i].t - 1)%mod;
            }
        }
        add(dp[v[i].pos], {1, nr});
        /// find the before
        nr = 0;
        ll nr2 = 0;
        for(auto j:x){
            if(j == v[i].pos){
                break;
            }
            if(j < v[i].pos){
                ///targeting this poll
                assert(dp2[j].nr == dp3[j].nr);
                nr2 = 0;
                for(auto k:x){
                    if(j < k && k < v[i].pos)nr2++;
                }
                add(dp[v[i].pos], {dp2[j].nr + 1, 1ll*dp2[j].nr2*fastexp(v[i].t - 1, nr2)%mod*v[i].t%mod*fastexp(n, v[i].pos - j - 1 - nr2)%mod});
                add(dp[v[i].pos], {dp3[j].nr + 1, mod - 1ll*dp3[j].nr2*fastexp(v[i].t - 1, nr2)%mod*fastexp(n, v[i].pos - j - 1 - nr2)%mod});
                if(v[i].t > v2[j]){
                    add(dp[v[i].pos], {dp[j].nr + 1, 1ll*dp[j].nr2*fastexp(v[i].t - 1, nr2)%mod*fastexp(n, v[i].pos - j - 1 - nr2)%mod});
                }
            }
            ///exactly this poll!
        }
        /// what occurs when lca is i or j?
        /// bruteforce dp
        /// find the after
        for(auto j:x){
            if(j == v[i].pos){
                break;
            }
            if(v[i].pos < j){
                ///v[i].pos -> j
                nr2 = 0;
                for(auto k:x){
                    if(v[i].pos < k && k < j)nr2++;
                }
                add(dp2[j], {dp[v[i].pos].nr, 1ll*dp[v[i].pos].nr2*fastexp(n - v[i].t + 1, nr2)%mod*fastexp(n, j - v[i].pos - nr2 - 1)%mod});
                add(dp3[j], {dp[v[i].pos].nr, 1ll*dp[v[i].pos].nr2*fastexp(n - v[i].t + 1, nr2)%mod*v[i].t%mod*fastexp(n, j - v[i].pos - nr2 - 1)%mod});
                if(nr2 != 0 && v2[j] > v[i].t){
                    add(dp[j], {dp[v[i].pos].nr + 1, 1ll*dp[v[i].pos].nr2*fastexp(n - v[i].t + 1, nr2 - 1)%mod*fastexp(n, j - v[i].pos - nr2 - 1)%mod*(v2[j] - v[i].t)%mod});
                }else if(v2[j] > v[i].t){
                    add(dp[j], {dp[v[i].pos].nr + 1, 1ll*dp[v[i].pos].nr2*fastexp(n, j - v[i].pos - nr2 - 1)%mod});
                }
            }
        }
    }
    dpnode ans = {0, fastexp(n, n)};
    for(ll i = 0;i < n;i++){
        if(!v2[i])continue;
        //cout<<dp[i].nr<<' '<<dp[i].nr2<<'\n';
        auto x = touch(i);
        ll cnt = 0;
        for(auto j:x){
            if(i < j)cnt++;
        }
        //cout<<1ll*dp[i].nr2*fastexp(n - v2[i] + 1, cnt)%mod*fastexp(n, n - i - 1 - cnt)%mod<<'\n';
        add(ans, {dp[i].nr, 1ll*dp[i].nr2*fastexp(n - v2[i] + 1, cnt)%mod*fastexp(n, n - i - 1 - cnt)%mod});
    }
    cout<<m - ans.nr<<' '<<ans.nr2<<'\n';
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll t;
    cin>>t;
    while(t--)solve();
    return 0;
}
/**
1
8 8
1 2
2 1
3 4
4 3
5 6
6 5
7 8
8 7
**/

**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 that can stress-test the algorithm. Specifically, we should consider scenarios where the binary search logic might fail or where the constraints on the array and tests are pushed to their limits.

### Key Considerations:
1. **Unsorted Array**: The array is not guaranteed to be sorted, which can lead to issues with the binary search algorithm.
2. **Distinct Elements**: All `x_i` and `k_i` are distinct, which means each test case is unique.
3. **Minimum Removals**: The goal is to find the minimum number of tests to remove so that the remaining tests can be satisfied by some array.

### Challenging Scenarios:
1. **Reversed Order**: An array where the elements are in reverse order.
2. **Mixed Order**: An array where elements are mixed in a way that makes binary search fail.
3. **Edge Cases**: Tests where `x_i` and `k_i` are at the boundaries of the array.

### Example Test Input:
Let's create a test input with a small array and a few tests that will challenge the binary search and the dynamic programming logic.

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

### Explanation:
- **Array**: `[5, 4, 3, 2, 1]`
- **Tests**:
  - `(1, 5)`: The 1st element is 5.
  - `(2, 4)`: The 2nd element is 4.
  - `(3, 3)`: The 3rd element is 3.
  - `(4, 2)`: The 4th element is 2.
  - `(5, 1)`: The 5th element is 1.

### Why This Test Input is Challenging:
- **Reversed Order**: The array is in reverse order, which can make the binary search logic fail if it assumes the array is sorted.
- **Distinct Elements**: All `x_i` and `k_i` are distinct, ensuring that each test is unique.
- **Complete Array**: The tests cover all elements of the array, making it necessary to check the entire array.

### Expected Output:
- **Minimum Removals**: 0, because the array can satisfy all tests.
- **Number of Arrays**: 1, because there is only one array that satisfies all tests.

```plaintext
0 1
```

This test input should expose any issues in the binary search logic and the dynamic programming approach used 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: Court Blue (Hard Version)
time_limit_ms: 4000
memory_limit_mb: 512
Description: This is the hard version of the problem. In this version, it is not guaranteed that $n=m$, and the time limit is higher. You can make hacks only if both versions of the problem are solved.

In the court of the Blue King, Lelle and Flamm are having a performance match. The match consists of several rounds. In each round, either Lelle or Flamm wins.

Let $W_L$ and $W_F$ denote the number of wins of Lelle and Flamm, respectively. The Blue King considers a match to be successful if and only if:

  * after every round, $\gcd(W_L,W_F)\le 1$;    * at the end of the match, $W_L\le n, W_F\le m$.

Note that $\gcd(0,x)=\gcd(x,0)=x$ for every non-negative integer $x$.

Lelle and Flamm can decide to stop the match whenever they want, and the final score of the performance is $l \cdot W_L + f \cdot W_F$.

Please help Lelle and Flamm coordinate their wins and losses such that the performance is successful, and the total score of the performance is maximized.

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

The only line of each test case contains four integers $n$, $m$, $l$, $f$ ($2\leq n\leq m \leq 2\cdot 10^7$, $1\leq l,f \leq 10^9$): $n$, $m$ give the upper bound on the number of Lelle and Flamm's wins, $l$ and $f$ determine the final score of the performance.

Unusual additional constraint: it is guaranteed that, for each test, there are no pairs of test cases with the same pair of $n$, $m$.

Output: For each test case, output a single integer — the maximum total score of a successful performance.

Examples:
input:
8
3 4 2 5
4 4 1 4
6 6 2 2
7 9 2 3
8 9 9 1
2 7 1 4
5 9 1 4
5 6 6 7
output:
22
17
18
37
77
30
41
59

input:
2
3082823 20000000 1341 331
20000000 20000000 3 5
output:
10754065643
159999991

input:
1
139 1293 193 412
output:
559543

Note: In the first test case, a possible performance is as follows:

  * Flamm wins, $\gcd(0,1)=1$.    * Lelle wins, $\gcd(1,1)=1$.    * Flamm wins, $\gcd(1,2)=1$.    * Flamm wins, $\gcd(1,3)=1$.    * Flamm wins, $\gcd(1,4)=1$.    * Lelle and Flamm agree to stop the match.

The final score is $1\cdot2+4\cdot5=22$.

Buggy Code:
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define rep(i, x, y) for(int i = x; i <= y; ++ i)
#define mid ((l + r) >> 1)
#define pb push_back
#define i64 long long

const int N = 1e6 + 20;
const long long inf = 2e18;
const int M = 1e9 + 7;

vector <int> pr;
int n, vis[N * 20];
void sieve()
{
	n = 2e7;
	for(int i = 2; i <= n; ++ i)
	{
		if(vis[i]) continue;
		pr.pb(i);
		for(int j = i + i; j <= n; j += i)
			vis[j] = 1;
	}
//	int Las = 0, s = 0;
//	for(auto i: pr)
//		s = max(s, i - Las), Las = i;
//	cout << s << "\n";
}

int f[500][500];
int m, tsx, tsy;

int Solve(int x, int y, int mx, int my)
{
	rep(i, 0, mx) rep(j, 0, my) f[i][j] = 0;

	f[0][0] = 1;
	rep(i, 0, mx)
		rep(j, 0, my)
		{
			if(!i && !j) continue;
			if(__gcd(i + x, j + y) > 1) continue;
			if(!i) f[i][j] = f[i][j - 1];
			else if(!j) f[i][j] = f[i - 1][j];
			else f[i][j] = (f[i][j - 1] | f[i - 1][j]);
		}
	int ans = tsx * n + tsy;
	ans = max(ans, tsx + tsy * m);
	rep(i, 0, mx)
		rep(j, 0, my)
			if(f[i][j]) ans = max(ans, (x + i) * tsx + (y + j) * tsy);
	return ans;
}
void Main()
{
	cin >> n >> m >> tsx >> tsy;

	if(tsx < tsy) swap(tsx, tsy), swap(n, m);

	if(n == 2)
	{
		int ans = tsx + tsy * m;
		if(m % 2) ans = tsx * 2 + tsy * m;
		else ans = max(ans, tsx * 2 + tsy * (m - 1));
		cout << ans << "\n";
		return;
	}
	if(m == 2)
	{
		int ans = tsx * n + tsy;
		if(n % 2) ans = tsx * n + tsy * 2;
		else ans = max(ans, tsx * (n - 1) + tsy * 2);
		cout << ans << "\n";
		return;
	}
	int l = 0, r = pr.size() - 1, ans = 0;
	while(l <= r)
		if(pr[mid] <= n) ans = mid, l = mid + 1;
		else r = mid - 1;

	int x = pr[ans];

	l = 0, r = pr.size() - 1, ans = 0;
	while(l <= r)
		if(pr[mid] <= m) ans = mid, l = mid + 1;
		else r = mid - 1;
	int y = pr[ans], yy = y;

	ans = n * tsx + tsy;
	ans = max(ans, m * tsy + tsx);

	x = max(n - 100, 1LL);
	y = max(m - 100, 1LL);
	ans = max(ans, Solve(x, y, n - x, m - y));
	cout << ans << "\n";
}
signed main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	sieve();

	int T = 1;
	cin >> T;
	while(T --) Main();
	return 0;
}
/*
1
4 5 5 4

1
9 9 9 1
*/

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

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

Think step by step.

Response:
```plaintext
1
4 5 5 4
```


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Court Blue (Hard Version)
time_limit_ms: 4000
memory_limit_mb: 512
Description: This is the hard version of the problem. In this version, it is not guaranteed that $n=m$, and the time limit is higher. You can make hacks only if both versions of the problem are solved.

In the court of the Blue King, Lelle and Flamm are having a performance match. The match consists of several rounds. In each round, either Lelle or Flamm wins.

Let $W_L$ and $W_F$ denote the number of wins of Lelle and Flamm, respectively. The Blue King considers a match to be successful if and only if:

  * after every round, $\gcd(W_L,W_F)\le 1$;    * at the end of the match, $W_L\le n, W_F\le m$.

Note that $\gcd(0,x)=\gcd(x,0)=x$ for every non-negative integer $x$.

Lelle and Flamm can decide to stop the match whenever they want, and the final score of the performance is $l \cdot W_L + f \cdot W_F$.

Please help Lelle and Flamm coordinate their wins and losses such that the performance is successful, and the total score of the performance is maximized.

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

The only line of each test case contains four integers $n$, $m$, $l$, $f$ ($2\leq n\leq m \leq 2\cdot 10^7$, $1\leq l,f \leq 10^9$): $n$, $m$ give the upper bound on the number of Lelle and Flamm's wins, $l$ and $f$ determine the final score of the performance.

Unusual additional constraint: it is guaranteed that, for each test, there are no pairs of test cases with the same pair of $n$, $m$.

Output: For each test case, output a single integer — the maximum total score of a successful performance.

Examples:
input:
8
3 4 2 5
4 4 1 4
6 6 2 2
7 9 2 3
8 9 9 1
2 7 1 4
5 9 1 4
5 6 6 7
output:
22
17
18
37
77
30
41
59

input:
2
3082823 20000000 1341 331
20000000 20000000 3 5
output:
10754065643
159999991

input:
1
139 1293 193 412
output:
559543

Note: In the first test case, a possible performance is as follows:

  * Flamm wins, $\gcd(0,1)=1$.    * Lelle wins, $\gcd(1,1)=1$.    * Flamm wins, $\gcd(1,2)=1$.    * Flamm wins, $\gcd(1,3)=1$.    * Flamm wins, $\gcd(1,4)=1$.    * Lelle and Flamm agree to stop the match.

The final score is $1\cdot2+4\cdot5=22$.

Buggy Code:
bool M1;
#include<bits/stdc++.h>
#define look_memory cerr<<abs(&M2-&M1)/1024.0/1024<<'\n'
#define look_time cerr<<(clock()-Time)*1.0/CLOCKS_PER_SEC<<'\n'
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define ll long long
#define pii pair<int,int>
const int M=2e7+5;
ll ans;
vector<int> pr;
bool prime[M];
int n,m,l,f;
void init(){
	rep(i,2,2e7){
		if(!prime[i]) pr.pb(i);
		for(auto j:pr){
			if(i*j>2e7) break;
			prime[i*j]=true;
			if(i%j==0) break;
		}
	}
	pr.pb(1);
}
int gcd(int x,int y){
	if(!y) return x;
	return gcd(y,x%y);
}
void work(int x,int y){
	ans=max(ans,1ll*x*l+1ll*y*f);
	if(x<m){
		if(gcd(x+1,y)==1) work(x+1,y);
	}
	if(y<n){
		if(gcd(x,y+1)==1) work(x,y+1);
	}
}
void solve(){
	cin>>n>>m>>l>>f;
	ans=0;
	if(n<m) swap(n,m);
	if(n<=10&&m<=10){
		work(1,1);
		cout<<ans<<'\n';
		return;
	}
	int p=pr[upper_bound(pr.begin(),pr.end(),n)-pr.begin()-1];
	int id=upper_bound(pr.begin(),pr.end(),m)-pr.begin()-1;
	int q=pr[upper_bound(pr.begin(),pr.end(),m)-pr.begin()-1];
	if(q==p) q=pr[--id];
	if(2*q>n){
		work(q,p);
	}
	else{
		while(1){
			bool fl=false;
			rep(i,p+1,n){
				if(gcd(q,i)>1){
					fl=true;
					break;
				}
			}
			if(!fl) break;
			q=pr[--id];
		}
		work(q,p);
	}
	cout<<ans<<'\n';
}
bool M2;
int main(){
	int Time=clock();
	look_memory;
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	init();
	int t;
	cin>>t;
	while(t--) solve();
	look_time;
	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 2 1 1
```


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Court Blue (Hard Version)
time_limit_ms: 4000
memory_limit_mb: 512
Description: This is the hard version of the problem. In this version, it is not guaranteed that $n=m$, and the time limit is higher. You can make hacks only if both versions of the problem are solved.

In the court of the Blue King, Lelle and Flamm are having a performance match. The match consists of several rounds. In each round, either Lelle or Flamm wins.

Let $W_L$ and $W_F$ denote the number of wins of Lelle and Flamm, respectively. The Blue King considers a match to be successful if and only if:

  * after every round, $\gcd(W_L,W_F)\le 1$;    * at the end of the match, $W_L\le n, W_F\le m$.

Note that $\gcd(0,x)=\gcd(x,0)=x$ for every non-negative integer $x$.

Lelle and Flamm can decide to stop the match whenever they want, and the final score of the performance is $l \cdot W_L + f \cdot W_F$.

Please help Lelle and Flamm coordinate their wins and losses such that the performance is successful, and the total score of the performance is maximized.

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

The only line of each test case contains four integers $n$, $m$, $l$, $f$ ($2\leq n\leq m \leq 2\cdot 10^7$, $1\leq l,f \leq 10^9$): $n$, $m$ give the upper bound on the number of Lelle and Flamm's wins, $l$ and $f$ determine the final score of the performance.

Unusual additional constraint: it is guaranteed that, for each test, there are no pairs of test cases with the same pair of $n$, $m$.

Output: For each test case, output a single integer — the maximum total score of a successful performance.

Examples:
input:
8
3 4 2 5
4 4 1 4
6 6 2 2
7 9 2 3
8 9 9 1
2 7 1 4
5 9 1 4
5 6 6 7
output:
22
17
18
37
77
30
41
59

input:
2
3082823 20000000 1341 331
20000000 20000000 3 5
output:
10754065643
159999991

input:
1
139 1293 193 412
output:
559543

Note: In the first test case, a possible performance is as follows:

  * Flamm wins, $\gcd(0,1)=1$.    * Lelle wins, $\gcd(1,1)=1$.    * Flamm wins, $\gcd(1,2)=1$.    * Flamm wins, $\gcd(1,3)=1$.    * Flamm wins, $\gcd(1,4)=1$.    * Lelle and Flamm agree to stop the match.

The final score is $1\cdot2+4\cdot5=22$.

Buggy Code:
//cpp
//#define __filed_
//#define __fasIO_
//#define __subit_
#define __moret_

#ifndef __wht_pre_
#define __wht_pre_

#include <bits/stdc++.h>

using namespace std;

#ifdef ONLINE_JUDGE
#define __subit_
#undef __filed_
#endif

#ifndef __w_IO__
#define __w_IO__

namespace IO {
    #ifdef __fasIO_
    const int maxn = 1 << 20;
    char in[maxn + 1], out[maxn], *p1 = in, *p2 = in, *p3 = out;
    #define getchar() (p1 == p2 && (p2 = (p1 = in) + fread(in + 1, 1, maxn, stdin), p1 == p2) ? EOF : *( ++ p1))
    #define flush() (fwrite(out + 1, 1, p3 - out, stdout))
    #define putchar(x) (p3 == out + maxn && (flush() , p3 = out), *( ++ p3) = x)
    class Flush{public: ~Flush(){flush();}}_;
    #endif
    #define isdigit(x) ('0' <= x && x <= '9')

    inline void rd(char *x) {
        do *x = getchar();
        while (*x <= 32 || *x == 127);
        while (*x  > 32 && *x != 127)
            * ++ x = getchar();
        *x = 0;
    }

    template<typename _Tp>
    inline void rd(_Tp &x) {
        x = 0;
        bool fl(false);
        char ch;
        do ch = getchar(), fl |= ch == '-'; while (!isdigit(ch));
        do x = x * 10 + (ch ^ 48), ch = getchar(); while (isdigit(ch));
        if (fl) x = -x;
    }

    template<>
    inline void rd(char &x) {
        do x = getchar();
        while (x <= 32 || x == 127);
    }

    template<>
    inline void rd(std::string &x) {
        char c;
        x.clear();
        do c = getchar();
        while (c <= 32 || c == 127);
        while (c  > 32 && c != 127)
            x.push_back(c), c = getchar();
    }

    template<typename _Tp>
    inline void wr(_Tp x) {
        x < 0 ? x = -x, putchar('-') : 0;
        static short st[50], top(0);
        do st[ ++ top] = x % 10, x /= 10; while (x);
        while (top) putchar(st[top -- ] | 48);
    }

    template<>
    inline void wr(char c) {
        putchar(c);
    }

    template<>
    inline void wr(char* s) {
        while (*s)
            putchar(*s ++ );
    }

    template<>
    inline void wr(const char* s) {
        while (*s)
            putchar(*s ++ );
    }

    template<typename _Tp, typename ...Args>
    void rd(_Tp &&x, Args &&...args) {
        rd(x); rd(args...);
    }

    template<typename _Tp, typename ...Args>
    void wr(_Tp x, Args ...args) {
        wr(x); wr(args...);
    }

    #undef isdigit
}
//using namespace IO::us;

#endif

#define frer(x) freopen(x, "r", stdin)
#define frew(x) freopen(x, "w", stdout)
#ifdef __filed_
#define frei(x) frer(x ".in")
#define freo(x) frew(x ".out")
#define frea(x) frew(x ".ans")
#define fre(x) frei(x), freo(x)
#else
#define frei(x) void()
#define freo(x) void()
#define frea(x) void()
#define fre(x) void()
#endif

#ifdef __subit_
#define erd(...) void()
#define ewr(...) void()
#else
#define erd(...) rd(__VA_ARGS__)
#define ewr(...) wr(__VA_ARGS__)
#endif

int Turn;
#ifndef __moret_
#define rdT() Turn = 1
#else
#define rdT() rd(Turn)
#endif
using IO::rd;
using IO::wr;

#define EXPAND5(...) EXPAND4(EXPAND4(EXPAND4(EXPAND4(__VA_ARGS__))))
#define EXPAND4(...) EXPAND3(EXPAND3(EXPAND3(EXPAND3(__VA_ARGS__))))
#define EXPAND3(...) EXPAND2(EXPAND2(EXPAND2(EXPAND2(__VA_ARGS__))))
#define EXPAND2(...) EXPAND1(EXPAND1(EXPAND1(EXPAND1(__VA_ARGS__))))
#define EXPAND1(...) __VA_ARGS__
#define PARENS ()

#endif

#define int long long

const int N = 2e7 + 7;

int pri[N];
int vis[N];
int low[N];
int pnt;

inline void INIT() {
    pri[0] = 1;
    for (int i = 2; i < N; ++ i) {
        if (!vis[i]) {
            ++ pnt;
            pri[pnt] = i;
            low[i] = i;
        }
        for (int j = 1; j <= pnt && i * pri[j] < N; ++ j) {
            vis[i * pri[j]] = 1;
            low[i * pri[j]] = pri[j];
            if (i % pri[j] == 0) {
                break;
            }
        }
    }
}

inline void WORK() {
    int n, m;
    int a, b;
    rd(n, m, a, b);
    if (a < b) swap(a, b), swap(n, m);
    int idx = upper_bound(pri, pri + pnt + 1, n) - pri - 1;
    int idy = upper_bound(pri, pri + pnt + 1, m) - pri - 1;
    int x, y;
    deque<pair<int, int>> q;
    set<int> se;
    int ans = 0;
    auto add = [&](int x, int y) -> void {
        ans = max(ans, x * a + y * b);
        if (!se.count(x * N + y)) {
            se.insert(x * N + y);
            q.push_back({x, y});
        }
    };
    if (idx == idy) {
        add(pri[idx - 1], pri[idy]);
        add(pri[idx], pri[idy - 1]);
    } else {
        add(pri[idx], pri[idy]);
    }
    add(n - 1, 1);
    add(1, m - 1);

    while (!q.empty()) {
        auto t = q.back();
        q.pop_back();
        x = t.first;
        y = t.second;
        if (x < n && __gcd(x + 1, y) == 1 && !se.count((x + 1) * N + y)) {
            add(x + 1, y);
        }
        if (y < m && __gcd(x, y + 1) == 1 && !se.count(x * N + y + 1)) {
            add(x, y + 1);
        }
    }
    wr(ans, '\n');
}

#undef int

int main() {
    fre("");
    INIT();
    for (rdT(); Turn; -- Turn, ewr('\n'))
        WORK();
    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:
To generate a challenging test input that exposes the bug in the given 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 GCD Condition**: The GCD condition is crucial in this problem. We need to test cases where the GCD condition is close to failing, especially when the GCD is 1.
2. **Large Values for n and m**: Since the problem involves large values for \( n \) and \( m \), we should test with values close to the upper limit to ensure the algorithm handles them correctly.
3. **Different Values for l and f**: We should test cases where the values of \( l \) and \( f \) are significantly different to ensure the algorithm correctly maximizes the score.
4. **Multiple Test Cases**: We should 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
3 4 2 5
4 4 1 4
6 6 2 2
7 9 2 3
```

This test input includes:
- A case where \( n \) and \( m \) are small and the values of \( l \) and \( f \) are different.
- A case where \( n \) and \( m \) are equal.
- A case where \( n \) and \( m \) are small and the values of \( l \) and \( f \) are the same.
- A case where \( n \) and \( m \) are larger and the values of \( l \) and \( f \) are different.

These cases should help expose any bugs in the given buggy code.


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Court Blue (Hard Version)
time_limit_ms: 4000
memory_limit_mb: 512
Description: This is the hard version of the problem. In this version, it is not guaranteed that $n=m$, and the time limit is higher. You can make hacks only if both versions of the problem are solved.

In the court of the Blue King, Lelle and Flamm are having a performance match. The match consists of several rounds. In each round, either Lelle or Flamm wins.

Let $W_L$ and $W_F$ denote the number of wins of Lelle and Flamm, respectively. The Blue King considers a match to be successful if and only if:

  * after every round, $\gcd(W_L,W_F)\le 1$;    * at the end of the match, $W_L\le n, W_F\le m$.

Note that $\gcd(0,x)=\gcd(x,0)=x$ for every non-negative integer $x$.

Lelle and Flamm can decide to stop the match whenever they want, and the final score of the performance is $l \cdot W_L + f \cdot W_F$.

Please help Lelle and Flamm coordinate their wins and losses such that the performance is successful, and the total score of the performance is maximized.

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

The only line of each test case contains four integers $n$, $m$, $l$, $f$ ($2\leq n\leq m \leq 2\cdot 10^7$, $1\leq l,f \leq 10^9$): $n$, $m$ give the upper bound on the number of Lelle and Flamm's wins, $l$ and $f$ determine the final score of the performance.

Unusual additional constraint: it is guaranteed that, for each test, there are no pairs of test cases with the same pair of $n$, $m$.

Output: For each test case, output a single integer — the maximum total score of a successful performance.

Examples:
input:
8
3 4 2 5
4 4 1 4
6 6 2 2
7 9 2 3
8 9 9 1
2 7 1 4
5 9 1 4
5 6 6 7
output:
22
17
18
37
77
30
41
59

input:
2
3082823 20000000 1341 331
20000000 20000000 3 5
output:
10754065643
159999991

input:
1
139 1293 193 412
output:
559543

Note: In the first test case, a possible performance is as follows:

  * Flamm wins, $\gcd(0,1)=1$.    * Lelle wins, $\gcd(1,1)=1$.    * Flamm wins, $\gcd(1,2)=1$.    * Flamm wins, $\gcd(1,3)=1$.    * Flamm wins, $\gcd(1,4)=1$.    * Lelle and Flamm agree to stop the match.

The final score is $1\cdot2+4\cdot5=22$.

Buggy Code:
import math

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def initialize_dp_table(n, m, l, f):
    dp = [[0] * (m + 1) for _ in range(n + 1)]
    dp[1][0] = l
    dp[0][1] = f
    return dp

def update_dp_value(dp, i, j, l, f):
    if i > 0:
        dp[i][j] = max(dp[i][j], dp[i-1][j] + l)
    if j > 0:
        dp[i][j] = max(dp[i][j], dp[i][j-1] + f)

def fill_dp_table(dp, n, m, l, f):
    for i in range(n + 1):
        for j in range(m + 1):
            if gcd(i, j) <= 1:
                update_dp_value(dp, i, j, l, f)

def find_max_score(dp):
    return max(max(row) for row in dp)

def solve_test_case(n, m, l, f):
    dp = initialize_dp_table(n, m, l, f)
    fill_dp_table(dp, n, m, l, f)
    return find_max_score(dp)

if __name__ == "__main__":
    t = int(input())
    for _ in range(t):
        n, m, l, f = map(int, input().split())
        result = solve_test_case(n, m, l, f)
        print(result)

**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 2 1000000000 1000000000
```


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Court Blue (Hard Version)
time_limit_ms: 4000
memory_limit_mb: 512
Description: This is the hard version of the problem. In this version, it is not guaranteed that $n=m$, and the time limit is higher. You can make hacks only if both versions of the problem are solved.

In the court of the Blue King, Lelle and Flamm are having a performance match. The match consists of several rounds. In each round, either Lelle or Flamm wins.

Let $W_L$ and $W_F$ denote the number of wins of Lelle and Flamm, respectively. The Blue King considers a match to be successful if and only if:

  * after every round, $\gcd(W_L,W_F)\le 1$;    * at the end of the match, $W_L\le n, W_F\le m$.

Note that $\gcd(0,x)=\gcd(x,0)=x$ for every non-negative integer $x$.

Lelle and Flamm can decide to stop the match whenever they want, and the final score of the performance is $l \cdot W_L + f \cdot W_F$.

Please help Lelle and Flamm coordinate their wins and losses such that the performance is successful, and the total score of the performance is maximized.

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

The only line of each test case contains four integers $n$, $m$, $l$, $f$ ($2\leq n\leq m \leq 2\cdot 10^7$, $1\leq l,f \leq 10^9$): $n$, $m$ give the upper bound on the number of Lelle and Flamm's wins, $l$ and $f$ determine the final score of the performance.

Unusual additional constraint: it is guaranteed that, for each test, there are no pairs of test cases with the same pair of $n$, $m$.

Output: For each test case, output a single integer — the maximum total score of a successful performance.

Examples:
input:
8
3 4 2 5
4 4 1 4
6 6 2 2
7 9 2 3
8 9 9 1
2 7 1 4
5 9 1 4
5 6 6 7
output:
22
17
18
37
77
30
41
59

input:
2
3082823 20000000 1341 331
20000000 20000000 3 5
output:
10754065643
159999991

input:
1
139 1293 193 412
output:
559543

Note: In the first test case, a possible performance is as follows:

  * Flamm wins, $\gcd(0,1)=1$.    * Lelle wins, $\gcd(1,1)=1$.    * Flamm wins, $\gcd(1,2)=1$.    * Flamm wins, $\gcd(1,3)=1$.    * Flamm wins, $\gcd(1,4)=1$.    * Lelle and Flamm agree to stop the match.

The final score is $1\cdot2+4\cdot5=22$.

Buggy Code:
import math
gcd=math.gcd
x=int(input())
def score(wl,wf,l,f):
    return (l*wl+f*wf)
for i in range(x):
    s=input()
    p=s.split()
    n=int(p[0])
    m=int(p[1])
    l=int(p[2])
    f=int(p[3])
    c=[[0,0],[0,1],[1,0]]
    d=[]
    for i in range(1,n+1):
        for j in range(1,m+1):
            if gcd(i,j)==0 or gcd(i,j)==1:
                if [i-1,j] in c or [i,j-1] in c:
                    z=[i,j]
                    c.append(z)
    for i in c:
        d.append(score(int(i[0]),int(i[-1]),l,f))
    print(max(d))

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

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

Think step by step.

Response:
```plaintext
1
3 3 1 1
```


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Court Blue (Hard Version)
time_limit_ms: 4000
memory_limit_mb: 512
Description: This is the hard version of the problem. In this version, it is not guaranteed that $n=m$, and the time limit is higher. You can make hacks only if both versions of the problem are solved.

In the court of the Blue King, Lelle and Flamm are having a performance match. The match consists of several rounds. In each round, either Lelle or Flamm wins.

Let $W_L$ and $W_F$ denote the number of wins of Lelle and Flamm, respectively. The Blue King considers a match to be successful if and only if:

  * after every round, $\gcd(W_L,W_F)\le 1$;    * at the end of the match, $W_L\le n, W_F\le m$.

Note that $\gcd(0,x)=\gcd(x,0)=x$ for every non-negative integer $x$.

Lelle and Flamm can decide to stop the match whenever they want, and the final score of the performance is $l \cdot W_L + f \cdot W_F$.

Please help Lelle and Flamm coordinate their wins and losses such that the performance is successful, and the total score of the performance is maximized.

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

The only line of each test case contains four integers $n$, $m$, $l$, $f$ ($2\leq n\leq m \leq 2\cdot 10^7$, $1\leq l,f \leq 10^9$): $n$, $m$ give the upper bound on the number of Lelle and Flamm's wins, $l$ and $f$ determine the final score of the performance.

Unusual additional constraint: it is guaranteed that, for each test, there are no pairs of test cases with the same pair of $n$, $m$.

Output: For each test case, output a single integer — the maximum total score of a successful performance.

Examples:
input:
8
3 4 2 5
4 4 1 4
6 6 2 2
7 9 2 3
8 9 9 1
2 7 1 4
5 9 1 4
5 6 6 7
output:
22
17
18
37
77
30
41
59

input:
2
3082823 20000000 1341 331
20000000 20000000 3 5
output:
10754065643
159999991

input:
1
139 1293 193 412
output:
559543

Note: In the first test case, a possible performance is as follows:

  * Flamm wins, $\gcd(0,1)=1$.    * Lelle wins, $\gcd(1,1)=1$.    * Flamm wins, $\gcd(1,2)=1$.    * Flamm wins, $\gcd(1,3)=1$.    * Flamm wins, $\gcd(1,4)=1$.    * Lelle and Flamm agree to stop the match.

The final score is $1\cdot2+4\cdot5=22$.

Buggy Code:
def gcd(num1, num2):
    if num1 == 0 or num2 == 0:
        return num1 + num2
    if num1 == num2:
        return num1
    if num1 > num2:
        return gcd(num1 - num2, num2)
    else:
        return gcd(num1, num2 - num1)
x=int(input())
def score(wl,wf,l,f):
    return (l*wl+f*wf)
for i in range(x):
    s=input()
    p=s.split()
    n=int(p[0])
    m=int(p[1])
    l=int(p[2])
    f=int(p[3])
    c=[[0,0],[0,1],[1,0]]
    d=[]
    for i in range(1,n+1):
        for j in range(1,m+1):
            if gcd(i,j)==0 or gcd(i,j)==1:
                if [i-1,j] in c or [i,j-1] in c:
                    z=[i,j]
                    c.append(z)
    for i in c:
        d.append(score(int(i[0]),int(i[-1]),l,f))
    print(max(d))

**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 3 1000000000 1
```

**Explanation:**
- The test case is designed to maximize the score by leveraging the high value of `l` (1000000000) and the small value of `m` (3).
- With `n = 2` and `m = 3`, the possible successful performances are:
  - (0, 1) -> GCD(0, 1) = 1
  - (1, 1) -> GCD(1, 1) = 1
  - (1, 2) -> GCD(1, 2) = 1
  - (1, 3) -> GCD(1, 3) = 1
- The maximum score is achieved by having Lelle win 1 time and Flamm win 3 times, resulting in a score of `1 * 1000000000 + 3 * 1 = 1000000003`.

This test case will expose the bug in the given code, as the code may not handle the high value of `l` and the small value of `m` correctly, leading to incorrect results.


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Court Blue (Hard Version)
time_limit_ms: 4000
memory_limit_mb: 512
Description: This is the hard version of the problem. In this version, it is not guaranteed that $n=m$, and the time limit is higher. You can make hacks only if both versions of the problem are solved.

In the court of the Blue King, Lelle and Flamm are having a performance match. The match consists of several rounds. In each round, either Lelle or Flamm wins.

Let $W_L$ and $W_F$ denote the number of wins of Lelle and Flamm, respectively. The Blue King considers a match to be successful if and only if:

  * after every round, $\gcd(W_L,W_F)\le 1$;    * at the end of the match, $W_L\le n, W_F\le m$.

Note that $\gcd(0,x)=\gcd(x,0)=x$ for every non-negative integer $x$.

Lelle and Flamm can decide to stop the match whenever they want, and the final score of the performance is $l \cdot W_L + f \cdot W_F$.

Please help Lelle and Flamm coordinate their wins and losses such that the performance is successful, and the total score of the performance is maximized.

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

The only line of each test case contains four integers $n$, $m$, $l$, $f$ ($2\leq n\leq m \leq 2\cdot 10^7$, $1\leq l,f \leq 10^9$): $n$, $m$ give the upper bound on the number of Lelle and Flamm's wins, $l$ and $f$ determine the final score of the performance.

Unusual additional constraint: it is guaranteed that, for each test, there are no pairs of test cases with the same pair of $n$, $m$.

Output: For each test case, output a single integer — the maximum total score of a successful performance.

Examples:
input:
8
3 4 2 5
4 4 1 4
6 6 2 2
7 9 2 3
8 9 9 1
2 7 1 4
5 9 1 4
5 6 6 7
output:
22
17
18
37
77
30
41
59

input:
2
3082823 20000000 1341 331
20000000 20000000 3 5
output:
10754065643
159999991

input:
1
139 1293 193 412
output:
559543

Note: In the first test case, a possible performance is as follows:

  * Flamm wins, $\gcd(0,1)=1$.    * Lelle wins, $\gcd(1,1)=1$.    * Flamm wins, $\gcd(1,2)=1$.    * Flamm wins, $\gcd(1,3)=1$.    * Flamm wins, $\gcd(1,4)=1$.    * Lelle and Flamm agree to stop the match.

The final score is $1\cdot2+4\cdot5=22$.

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

public class Main {
    private static BufferedReader br;
    private static StringTokenizer tokenizer;
    private static String next() throws IOException{
        if (br == null) br = new BufferedReader(new InputStreamReader(System.in));
        if (tokenizer == null) tokenizer = new StringTokenizer(br.readLine());
        while (!tokenizer.hasMoreTokens()) tokenizer = new StringTokenizer(br.readLine());
        return tokenizer.nextToken();
    }
    private static int nextInt() throws IOException{
        return Integer.parseInt(next());
    }
    private static long nextLong() throws IOException{
        return Long.parseLong(next());
    }

    static StringBuilder sb = new StringBuilder();

    static List<Integer> primes;
    static int sup = 20_000_002;
    static int[] prePrimes = new int[sup];
    static int[] minPrimes = new int[sup];
    static int[][] direction = {{1,0},{0,1}};
    static long[][] visited;
    static int n;
    static int m;
    static long l;
    static long f;
    static Map<Long, Long> cached;

    static void getPrimes() {
        boolean[] visited = new boolean[sup];
        primes = new ArrayList<>();
        prePrimes[1] = prePrimes[2] = 1;
        minPrimes[1] = 1;
        for (int i = 2; i < sup; ++i) {
            if (i > 2) prePrimes[i] = primes.get(primes.size() - 1);
            if (!visited[i]) {
                minPrimes[i] = i;
                primes.add(i);
            }
            for (int p : primes) {
                if (i * p >= sup) break;
                visited[i * p] = true;
                minPrimes[i * p] = p;
                if (i % p == 0) {
                    break;
                }
            }
        }
    }

    static long gcd(int x, int y) {
        if (x < y) {
            int t = x; x = y; y = t;
        }
        if (x % y == 0) return y;
        return gcd(y, x % y);
    }

    static long getKey(long x, long y) {
        return x * sup + y;
    }

    static long dfs(int p, int q, long l, long f, int n, int m, int flag) {
//        System.out.println("p:"+p+",q:"+q);
        if (p > n || q > m || gcd(p, q) > 1 || p < q) return 0L;
        long key = getKey(p, q);
        if (cached.containsKey(key)) return cached.get(key);
        long ans = flag == 0 ? Math.max(l * p + f * q, l * q + f * p) : l * p + f * q;
        for (int[] d : direction) {
            ans = Math.max(ans, dfs(p + d[0], q + d[1], l, f, n, m, flag));
        }
        cached.put(key, ans);
        return ans;
    }

    static void slove() throws IOException{
        n = nextInt(); m = nextInt(); l = nextInt(); f = nextInt();
        // System.out.println(n + "," + m + "," + l + "," + f);
        if (n < m) {
            int t = n; n = m; m = t; long t2 = l; l = f; f = t2;
        }

        if (n == 1) {
            sb.append(l + f).append("\n");
            return;
        }

        int lp = prePrimes[m + 1];
        int lq = prePrimes[lp];
        if (m < 200) {
            lp = lq = 1;
        }
        cached = new HashMap<>();
        long ans = 0L;
        for (int i = lq; i <= m; ++i) ans = Math.max(ans, dfs(lp, i, l, f, m, m, 0));
        for (int i = lp; i <= m; ++i) ans = Math.max(ans, dfs(i, lq, l, f, m, m, 0));

        int p = prePrimes[n + 1];
        int q = m;
        while (q > 1) {
            boolean flag = true;
            int tq = q;
            while (tq > 1) {
                // System.out.println(tq);
                int mq = minPrimes[tq];
                if ((p % mq) + (n - p) >= mq) {
                    flag = false;
                    break;
                }
                while (tq % mq == 0) tq /= mq;
            }
            if (flag) break;;
            --q;
        }
        if (n < 200) {
            p = q = 1;
        }
        // System.out.println("q:" + q + ", p:" + p);
        cached = new HashMap<>();

        for (int i = q; i <= m; ++i) ans = Math.max(ans, dfs(p, i, l, f, n, m, 1));
        for (int i = p; i <= n; ++i) ans = Math.max(ans, dfs(i, q, l, f, n, m, 1));
        sb.append(ans).append("\n");

    }

    public static void main(String[] args)  throws IOException {
        getPrimes();
        int tt = nextInt();
        sb = new StringBuilder();
        for (int i = 0; i < tt; ++i) slove();
        System.out.println(sb);
    }
}

**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
2 2 1 1
2 2 2 1
2 2 1 2
```


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Court Blue (Hard Version)
time_limit_ms: 4000
memory_limit_mb: 512
Description: This is the hard version of the problem. In this version, it is not guaranteed that $n=m$, and the time limit is higher. You can make hacks only if both versions of the problem are solved.

In the court of the Blue King, Lelle and Flamm are having a performance match. The match consists of several rounds. In each round, either Lelle or Flamm wins.

Let $W_L$ and $W_F$ denote the number of wins of Lelle and Flamm, respectively. The Blue King considers a match to be successful if and only if:

  * after every round, $\gcd(W_L,W_F)\le 1$;    * at the end of the match, $W_L\le n, W_F\le m$.

Note that $\gcd(0,x)=\gcd(x,0)=x$ for every non-negative integer $x$.

Lelle and Flamm can decide to stop the match whenever they want, and the final score of the performance is $l \cdot W_L + f \cdot W_F$.

Please help Lelle and Flamm coordinate their wins and losses such that the performance is successful, and the total score of the performance is maximized.

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

The only line of each test case contains four integers $n$, $m$, $l$, $f$ ($2\leq n\leq m \leq 2\cdot 10^7$, $1\leq l,f \leq 10^9$): $n$, $m$ give the upper bound on the number of Lelle and Flamm's wins, $l$ and $f$ determine the final score of the performance.

Unusual additional constraint: it is guaranteed that, for each test, there are no pairs of test cases with the same pair of $n$, $m$.

Output: For each test case, output a single integer — the maximum total score of a successful performance.

Examples:
input:
8
3 4 2 5
4 4 1 4
6 6 2 2
7 9 2 3
8 9 9 1
2 7 1 4
5 9 1 4
5 6 6 7
output:
22
17
18
37
77
30
41
59

input:
2
3082823 20000000 1341 331
20000000 20000000 3 5
output:
10754065643
159999991

input:
1
139 1293 193 412
output:
559543

Note: In the first test case, a possible performance is as follows:

  * Flamm wins, $\gcd(0,1)=1$.    * Lelle wins, $\gcd(1,1)=1$.    * Flamm wins, $\gcd(1,2)=1$.    * Flamm wins, $\gcd(1,3)=1$.    * Flamm wins, $\gcd(1,4)=1$.    * Lelle and Flamm agree to stop the match.

The final score is $1\cdot2+4\cdot5=22$.

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

public class Main {
    private static BufferedReader br;
    private static StringTokenizer tokenizer;
    private static String next() throws IOException{
        if (br == null) br = new BufferedReader(new InputStreamReader(System.in));
        if (tokenizer == null) tokenizer = new StringTokenizer(br.readLine());
        while (!tokenizer.hasMoreTokens()) tokenizer = new StringTokenizer(br.readLine());
        return tokenizer.nextToken();
    }
    private static int nextInt() throws IOException{
        return Integer.parseInt(next());
    }
    private static long nextLong() throws IOException{
        return Long.parseLong(next());
    }

    static StringBuilder sb = new StringBuilder();

    static List<Integer> primes;
    static int sup = 20_000_002;
    static int[] prePrimes = new int[sup];
    static int[] minPrimes = new int[sup];
    static int[][] direction = {{1,0},{0,1}};
    static long[][] visited;
    static int n;
    static int m;
    static long l;
    static long f;
    static Map<Long, Long> cached;

    static void getPrimes() {
        boolean[] visited = new boolean[sup];
        primes = new ArrayList<>();
        prePrimes[1] = prePrimes[2] = 1;
        minPrimes[1] = 1;
        for (int i = 2; i < sup; ++i) {
            if (i > 2) prePrimes[i] = primes.get(primes.size() - 1);
            if (!visited[i]) {
                minPrimes[i] = i;
                primes.add(i);
            }
            for (int p : primes) {
                if (i * p >= sup) break;
                visited[i * p] = true;
                minPrimes[i * p] = p;
                if (i % p == 0) {
                    break;
                }
            }
        }
    }

    static long gcd(int x, int y) {
        if (x < y) {
            int t = x; x = y; y = t;
        }
        if (x % y == 0) return y;
        return gcd(y, x % y);
    }

    static long getKey(long x, long y) {
        return x * sup + y;
    }

    static long dfs(int p, int q, long l, long f, int n, int m, int flag) {
        if (p > n || q > m || gcd(p, q) > 1 || p < q) return 0L;
        long key = getKey(p, q);
        if (cached.containsKey(key)) return cached.get(key);
        long ans = flag == 0 ? Math.max(l * p + f * q, l * q + f * p) : l * p + f * q;
        for (int[] d : direction) {
            ans = Math.max(ans, dfs(p + d[0], q + d[1], l, f, n, m, flag));
        }
        cached.put(key, ans);
        return ans;
    }

    static void slove() throws IOException{
        n = nextInt(); m = nextInt(); l = nextInt(); f = nextInt();
        // System.out.println(n + "," + m + "," + l + "," + f);
        if (n < m) {
            int t = n; n = m; m = t; long t2 = l; l = f; f = t2;
        }

        if (n == 1) {
            sb.append(l + f).append("\n");
            return;
        }

        int lp = prePrimes[m + 1];
        int lq = prePrimes[lp];
        if (m < 200) {
            lp = lq = 1;
        }
        cached = new HashMap<>();
        long ans = 0L;
        for (int i = lq; i <= m; ++i) ans = Math.max(ans, dfs(lp, i, l, f, m, m, 0));
        for (int i = lp; i <= m; ++i) ans = Math.max(ans, dfs(i, lq, l, f, m, m, 0));

        int p = prePrimes[n + 1];
        int q = m;
        while (q > 1) {
            boolean flag = true;
            int tq = q;
            while (tq > 1) {
                // System.out.println(tq);
                int mq = minPrimes[tq];
                if ((p % mq) + (n - p) >= mq) {
                    flag = false;
                    break;
                }
                if (!flag) break;
                while (tq % mq == 0) tq /= mq;
            }

            --q;
        }
        if (n < 200) {
            p = q = 1;
        }
        // System.out.println("q:" + q + ", p:" + p);
        cached = new HashMap<>();

        for (int i = q; i <= m; ++i) ans = Math.max(ans, dfs(p, i, l, f, n, m, 1));
        for (int i = p; i <= n; ++i) ans = Math.max(ans, dfs(i, q, l, f, n, m, 1));
        sb.append(ans).append("\n");

    }

    public static void main(String[] args)  throws IOException {
        getPrimes();
        int tt = nextInt();
        sb = new StringBuilder();
        for (int i = 0; i < tt; ++i) slove();
        System.out.println(sb);
    }
}

**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 focus on edge cases and scenarios that are likely to cause issues. The primary issues in the code seem to be related to the handling of prime numbers, the GCD condition, and the dynamic programming (DP) approach used.

### Step-by-Step Analysis:
1. **Prime Number Handling**: The code uses a precomputed list of primes and a `prePrimes` array to optimize the search. However, the way it handles prime numbers and their multiples can be problematic, especially for large values of `n` and `m`.

2. **GCD Condition**: The GCD condition must be satisfied after every round. The code checks this condition in the `dfs` function, but the way it handles the GCD calculation and the recursive calls might not be optimal for certain edge cases.

3. **Dynamic Programming**: The DP approach used in the `dfs` function might not handle all possible states correctly, especially for large values of `n` and `m`.

### Challenging Test Input:
To expose these issues, we can create a test case where `n` and `m` are relatively large, and the values of `l` and `f` are such that the GCD condition is more likely to be violated. Additionally, we can use values that are close to the limits of the constraints to ensure the code handles them correctly.

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

```plaintext
1
100 100 100 100
```

### Explanation:
- **Test Case**: This test case has `n = 100`, `m = 100`, `l = 100`, and `f = 100`.
- **Reasoning**:
  - **Large Values**: The values of `n` and `m` are large enough to test the prime handling and GCD condition.
  - **Equal Weights**: The values of `l` and `f` are equal, which means the score is maximized by balancing the wins of Lelle and Flamm.
  - **GCD Condition**: The GCD condition must be checked after every round, and with `n` and `m` being 100, there are multiple combinations to test.

This test case should help identify any issues in the code, particularly in the handling of prime numbers and the GCD condition. If the code fails to handle this test case correctly, it will likely expose the bugs in the prime number handling and the GCD condition checks.


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Court Blue (Hard Version)
time_limit_ms: 4000
memory_limit_mb: 512
Description: This is the hard version of the problem. In this version, it is not guaranteed that $n=m$, and the time limit is higher. You can make hacks only if both versions of the problem are solved.

In the court of the Blue King, Lelle and Flamm are having a performance match. The match consists of several rounds. In each round, either Lelle or Flamm wins.

Let $W_L$ and $W_F$ denote the number of wins of Lelle and Flamm, respectively. The Blue King considers a match to be successful if and only if:

  * after every round, $\gcd(W_L,W_F)\le 1$;    * at the end of the match, $W_L\le n, W_F\le m$.

Note that $\gcd(0,x)=\gcd(x,0)=x$ for every non-negative integer $x$.

Lelle and Flamm can decide to stop the match whenever they want, and the final score of the performance is $l \cdot W_L + f \cdot W_F$.

Please help Lelle and Flamm coordinate their wins and losses such that the performance is successful, and the total score of the performance is maximized.

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

The only line of each test case contains four integers $n$, $m$, $l$, $f$ ($2\leq n\leq m \leq 2\cdot 10^7$, $1\leq l,f \leq 10^9$): $n$, $m$ give the upper bound on the number of Lelle and Flamm's wins, $l$ and $f$ determine the final score of the performance.

Unusual additional constraint: it is guaranteed that, for each test, there are no pairs of test cases with the same pair of $n$, $m$.

Output: For each test case, output a single integer — the maximum total score of a successful performance.

Examples:
input:
8
3 4 2 5
4 4 1 4
6 6 2 2
7 9 2 3
8 9 9 1
2 7 1 4
5 9 1 4
5 6 6 7
output:
22
17
18
37
77
30
41
59

input:
2
3082823 20000000 1341 331
20000000 20000000 3 5
output:
10754065643
159999991

input:
1
139 1293 193 412
output:
559543

Note: In the first test case, a possible performance is as follows:

  * Flamm wins, $\gcd(0,1)=1$.    * Lelle wins, $\gcd(1,1)=1$.    * Flamm wins, $\gcd(1,2)=1$.    * Flamm wins, $\gcd(1,3)=1$.    * Flamm wins, $\gcd(1,4)=1$.    * Lelle and Flamm agree to stop the match.

The final score is $1\cdot2+4\cdot5=22$.

Buggy Code:
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=2e7+5;
bool isp[N];
vector<int> p={1};
auto init=[](){
	for(int i=2;i<N;i++){
		if(!isp[i]) p.push_back(i);
		for(auto v:p){
			if(v==1) continue;
			if(i*v>=N) break;
			isp[i*v]=true;
			if(i%v==0) break;
		}
	}
	return 0;
}();
auto solve(int n,int m,int l,int f){
	auto find=[&](int n){
		auto it=lower_bound(begin(p),end(p),n);
		if(it!=p.begin()) it=prev(it);
		return *it;
	};
	int x=find(n);
	m=min(m,n);
	int y=find(min(x,m));
	if(n<50) x=1;
	if(m<50) y=1;
	int p=n-x,q=m-y;
	vector dp(p+1,vector<int>(q+1));
	dp[0][0]=1;
	ll ans=0;
	for(int i=0;i<=p;i++){
		for(int j=0;j<=q;j++){
			if(!dp[i][j]) continue;
			int s=i+x,t=j+y;
			if(s+1<=n&&__gcd(s+1,t)==1) dp[i+1][j]=1;
			if(t+1<=m&&__gcd(s,t+1)==1) dp[i][j+1]=1;
			ans=max(ans,1ll*l*s+1ll*f*t);
		}
	}
	return ans;
}
auto solve2(int n,int m,int l,int f){
	if(m>=n) return 0ll;
	auto find=[&](int n){
		auto it=lower_bound(begin(p),end(p),n);
		if(it!=p.begin()) it=prev(it);
		return *it;
	};
	int y=find(m);
	n=min(n,2*y);
	int x=find(n);
	y=find(min(x,m));
	if(n<50) x=1;
	if(m<50) y=1;
	if(x<=y) return 0ll;
	int p=n-x,q=m-y;
	vector dp(p+1,vector<int>(q+1));
	dp[0][0]=1;
	ll ans=0;
	for(int i=0;i<=p;i++){
		for(int j=0;j<=q;j++){
			if(!dp[i][j]) continue;
			int s=i+x,t=j+y;
			if(s+1<=n&&__gcd(s+1,t)==1) dp[i+1][j]=1;
			if(t+1<=m&&__gcd(s,t+1)==1) dp[i][j+1]=1;
			ans=max(ans,1ll*l*s+1ll*f*t);
		}
	}
	return ans;
}
auto solve(){
	int n,m,l,f;
	cin>>n>>m>>l>>f;
	return max({
		solve(n,m,l,f),solve(m,n,f,l),
		solve2(n,m,l,f),solve2(m,n,f,l)});
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
	int t=1;
	cin>>t;
	while(t--){
		// solve();
		cout<<solve()<<'\n';
		// cout<<(solve()?"YES":"NO")<<'\n';
	}
	return 0;
}

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

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

Think step by step.

Response:
To generate a challenging test input that exposes the bug in the provided code, we need to focus on edge cases that are likely to cause issues. Here are the steps to create such a test input:

1. **Identify the Bug**: The code uses a precomputed list of prime numbers to find the largest prime less than or equal to a given number. The bug might be related to the handling of small values of `n` and `m`, or the dynamic programming (DP) approach might not correctly handle certain transitions.

2. **Edge Cases**:
   - **Small Values**: Test cases where `n` and `m` are small (e.g., 2, 3, 4) to check if the code handles small values correctly.
   - **Equal Values**: Test cases where `n` and `m` are equal to ensure the code handles this scenario correctly.
   - **Large Values**: Test cases where `n` and `m` are large (e.g., close to the upper limit) to check the performance and correctness of the code.
   - **Special Values**: Test cases where `n` and `m` are prime numbers or powers of small primes to check if the code correctly finds the largest prime less than or equal to these values.

3. **Generate the Test Input**:
   - We will create a small-scale test input with a few test cases that cover the above edge cases.

Here is the test input:

```plaintext
4
2 3 1 1
3 3 1 1
10 10 1 1
19999999 20000000 1 1
```

### Explanation:
1. **Test Case 1**: `2 3 1 1`
   - `n` and `m` are small, and `l` and `f` are both 1.
   - This tests the handling of small values and the correctness of the DP approach.

2. **Test Case 2**: `3 3 1 1`
   - `n` and `m` are equal, and `l` and `f` are both 1.
   - This tests the handling of equal values and ensures the code does not get stuck in a loop or incorrectly handle the GCD condition.

3. **Test Case 3**: `10 10 1 1`
   - `n` and `m` are larger but still manageable, and `l` and `f` are both 1.
   - This tests the correctness of the DP approach for larger values and the handling of multiple rounds.

4. **Test Case 4**: `19999999 20000000 1 1`
   - `n` and `m` are close to the upper limit, and `l` and `f` are both 1.
   - This tests the performance and correctness of the code for large values and ensures it can handle the upper bounds efficiently.

This test input should help expose any bugs in the provided code by covering a range of edge cases.


**Task:**
Generate a challenging test input that exposes the bug in the buggy code of the algorithm problem:
Algorithm Problem:
Title: Court Blue (Hard Version)
time_limit_ms: 4000
memory_limit_mb: 512
Description: This is the hard version of the problem. In this version, it is not guaranteed that $n=m$, and the time limit is higher. You can make hacks only if both versions of the problem are solved.

In the court of the Blue King, Lelle and Flamm are having a performance match. The match consists of several rounds. In each round, either Lelle or Flamm wins.

Let $W_L$ and $W_F$ denote the number of wins of Lelle and Flamm, respectively. The Blue King considers a match to be successful if and only if:

  * after every round, $\gcd(W_L,W_F)\le 1$;    * at the end of the match, $W_L\le n, W_F\le m$.

Note that $\gcd(0,x)=\gcd(x,0)=x$ for every non-negative integer $x$.

Lelle and Flamm can decide to stop the match whenever they want, and the final score of the performance is $l \cdot W_L + f \cdot W_F$.

Please help Lelle and Flamm coordinate their wins and losses such that the performance is successful, and the total score of the performance is maximized.

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

The only line of each test case contains four integers $n$, $m$, $l$, $f$ ($2\leq n\leq m \leq 2\cdot 10^7$, $1\leq l,f \leq 10^9$): $n$, $m$ give the upper bound on the number of Lelle and Flamm's wins, $l$ and $f$ determine the final score of the performance.

Unusual additional constraint: it is guaranteed that, for each test, there are no pairs of test cases with the same pair of $n$, $m$.

Output: For each test case, output a single integer — the maximum total score of a successful performance.

Examples:
input:
8
3 4 2 5
4 4 1 4
6 6 2 2
7 9 2 3
8 9 9 1
2 7 1 4
5 9 1 4
5 6 6 7
output:
22
17
18
37
77
30
41
59

input:
2
3082823 20000000 1341 331
20000000 20000000 3 5
output:
10754065643
159999991

input:
1
139 1293 193 412
output:
559543

Note: In the first test case, a possible performance is as follows:

  * Flamm wins, $\gcd(0,1)=1$.    * Lelle wins, $\gcd(1,1)=1$.    * Flamm wins, $\gcd(1,2)=1$.    * Flamm wins, $\gcd(1,3)=1$.    * Flamm wins, $\gcd(1,4)=1$.    * Lelle and Flamm agree to stop the match.

The final score is $1\cdot2+4\cdot5=22$.

Buggy Code:
#include<bits/stdc++.h>
using namespace std;
const int N = 2e7 + 1000;
int fl[N + 10], p[N], tot;
long long ans;
int G[1100][1100], FL, L, F;
void calc(int x, int y, int Lx, int Rx, int Ly, int Ry) {
	// if(Ly > R)return;
	if(__gcd(x, y) > 1)return;
	if(G[x - Lx][y - Ly] == FL)return;
	G[x - Lx][y - Ly] = FL;
	ans = max(ans, 1ll * x * L + 1ll * y * F);
	if(x < y && x < Rx) {
		calc(x + 1, y, Lx, Rx, Ly, Ry);
	}
	if(y < Ry) {
		calc(x, y + 1, Lx, Rx, Ly, Ry);
	}
}
void work(int n, int m, int l, int f) {
	L = l;
	F = f;
	if(m <= 200) {
		FL++;
		calc(1, 1, 1, n, 1, m);
		return;
	}
	int t = upper_bound(p + 1, p + tot + 1, m) - p - 1;
	int q = upper_bound(p + 1, p + tot + 1, min(p[t] - 1, n)) - p - 1;
	for(int i = q; i >= 1 && i >= q - 10; i--) {
		FL++;
		calc(p[i], p[t], p[i], n, p[t], m);
	}
}
int main() {
	int T;
	for(int i = 2; i <= N; i++) {
		if(!fl[i])p[++tot] = i;
		else continue;
		for(int j = i; 1ll * i * j <= N; j++)
			fl[i * j] = 1;
	}
	// cout<<p[m]<<endl;
	scanf("%d", &T);
	while(T--) {
		int n, m, l, f;
		scanf("%d%d%d%d", &n, &m, &l, &f);
		ans = 0;
		work(n, m, l, f);
		work(m, n, f, l);
		printf("%lld\n", 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
2
3 4 1 10
4 3 10 1
```