fork download
  1. for _ in range(int(input())):
  2. N,M=map(int,input().split())
  3. _count=0
  4. X=1
  5. Y=1
  6. for _ in range(int(input())):
  7. _flag=True
  8. _in_x,_in_y=map(int,input().split())
  9. while _flag==True:
  10. if ((X+_in_x)<=N and (Y+_in_y)<=M) and (X+_in_x)>0 and (Y+_in_y)>0:
  11. _count+=1
  12. X+=_in_x
  13. Y+=_in_y
  14. print("{},{}".format(X,Y))
  15. else:
  16. _flag=False
  17. print(_count)
Success #stdin #stdout 0.01s 28384KB
stdin
1
5 6
3
1 1
1 1
0 -4
stdout
2,2
3,3
4,4
5,5
5,1
5