@@ -0,0 +1,546 @@
+#!/usr/bin/env python%0Aimport math%0A%0Adef step(C) :%0A    if C == 0: return%0A    _  = input()%0A%0A    r, c = map(int, input().split())%0A    n = math.ceil((r+c)/2)%0A    m = r if r %3C= c else c%0A    d = abs(c - r)%0A%0A    print(n)%0A    for i in range(m):%0A        print(i, i)%0A%0A    for i in range(1, d, 2):%0A        if r %3C c: print(m - 1, m + i)%0A        else: print(m + i, m - 1)%0A%0A    if d %25 2:%0A        if r %3C c: print(m - 1, m + d - 1)%0A        else: print(m + d - 1, m - 1)%0A%0A    step(C-1)%0A%0Adef main():%0A    step (int(input()))%0A%0Aif __name__ == %22__main__%22 :%0A    main ()%0A

solve IPSC2017/A