TLE in KDIAMS

May someone please help me in understanding why this code doesn’t terminate correctly to give the output?

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb emplace_back
#define sz(x) (ll)x.size()
int N = 2e5 + 5;

void solve_test_case(){
ll n,k;
cin >> n >> k;
ll t = n * (n - 1) / 2;
if(t - n + 2 <= k && k <= t - 1){
cout << -1 << “\n”;
return;
}
else{
ll m = 0;
m = ((k == t) ? t : t - k);
vector<pair<int,int>> ans;
for (ll i = 0; i < n; i++)
{
for (ll j = i + 1; j < n; i++)
{
if(sz(ans) < m){
ans.emplace_back(i, j);
}
}
}
cout << m << “\n”;
for(auto [x,y] : ans){
cout << x + 1 << " " << y + 1 << “\n”;
}
}
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
for(int i = 1;i <= t;++i){
solve_test_case();
}
}