#include using namespace std; typedef long long ll; const int maxn=2e5+100; const int mod = 1e9+7; int a[1005]; int main() { int t; scanf("%d",&t); while(t--){ ll n,m; ll minn=1e18; scanf("%lld%lld",&n,&m); for(int i=0;i