#pragma GCC optimize("Ofast") #pragma GCC target("avx2") char*mmap(); #define rd_skip() while(*rp++>=48) #define rd(v) int v=0;{int _c;while(_c=*rp++-48,_c>=0)v=v*10+_c;} char wbuf[1<<28]; #define WTHI(v) {long _z=v,_n=0,_d=0;while(++_n,_d=_d<<8|0x30|_z%10,_z/=10);*(long*)wp=_d;wp+=_n;} #define WTLO(v) {long _z=v,_n=8,_d=0;while(_d=_d<<8|0x30|_z%10,_z/=10,--_n);*(long*)wp=_d;wp+=8;} #define wt(v) WTHI(v) main(){ char*rp=mmap(0l,1l<<28,1,2,0,0ll); char*wp=wbuf; rd_skip(); while(*rp){ rd(n); rd(m); if(n==1&&m==1){ *wp++='0'; *wp++='\n'; *wp++='1'; *wp++=' '; *wp++='1'; *wp++='\n'; continue; } if((n|m)&1){ *wp++='-'; *wp++='1'; *wp++='\n'; continue; } wt(m*n-1); *wp++='\n'; for(int y=0;y=0;){ wt(y+2); *wp++=' '; wt(x+2); *wp++='\n'; wt(y+1); *wp++=' '; wt(x+1); *wp++='\n'; wt(y+1); *wp++=' '; wt(x+2); *wp++='\n'; wt(y+2); *wp++=' '; wt(x+1); *wp++='\n'; } } } } write(1,wbuf,wp-wbuf); _exit(0); }