#include<iostream> #include<string> #include<iomanip> #include<cmath> #include<vector> #include<algorithm> #include<utility> using namespace std; #define int long long #define endl "\n" constexpr long long INF = (long long)1e18; constexpr long long MOD = 1'000'000'007; struct fast_io { fast_io(){ std::cin.tie(nullptr); std::ios::sync_with_stdio(false); }; } fio; int dy[] = {0, 0, 1, 1}; int dx[] = {0, 1, 0, 1}; #define x first #define y second void print(int ny, int nx, vector<int> v){ // cout<<" <><><> "<<" "<<ny<<" "<<nx<<endl; for(int i = 0; i < v.size(); i++){ cout<<ny+dy[v[i]]+1<<" "<<nx+dx[v[i]]+1<<endl; // cout<<dy[v[i]]<<" "<<dx[v[i]]<<" "<<v[i]<<endl; } } signed main(){ cout<<fixed<<setprecision(10); int T; cin>>T; for(int _ = 0; _ < T; _++){ int N, M; cin>>N>>M; if(N%2 || M%2) { if(N == 1 && M == 1) { cout<<0<<endl; cout<<1<<" "<<1<<endl; } else { cout<<-1<<endl; } } else { cout<<N * M -1<<endl; // cout<<2<<" "<<1<<endl; for(int i = 0; i < M; i += 4){ print(0, i, {2, 1, 0, 3}); for(int j = 2; j < N; j += 2){ print(j, i, {1, 2, 0, 3}); } if(i + 2 >= M) break; for(int j = N-2; j >= 2; j -= 2){ print(j, i+2, {2, 1, 3, 0}); } print(0, i+2, {2, 1, 0, 3}); } } } return 0; }