program choosing_points
  implicit none
  integer :: n, d1, d2, i, j, m, c(600,600,2) = 0, a, b, k
  read(*,*) n, d1, d2
  m = 2*n
  call coloring(c(1:m,1:m,1),d1)
  call coloring(c(1:m,1:m,2),d2)
  do a = 0, 1
    do b = 0, 1
      k = 0
      do i = 1, m
        do j = 1, m
          if (c(i,j,1) == a .and. c(i,j,2) == b) k = k+1
        end do
      end do
      if (k < n*n) cycle
      k = 0
      do i = 1, m
        do j = 1, m
          if (c(i,j,1) == a .and. c(i,j,2) == b) then
            write(*,'(i0,x,i0)') i-1, j-1
            k = k+1
            if (k == n*n) stop
          end if
        end do
      end do
    end do
  end do
  stop
contains
  recursive subroutine coloring(c,d)
    implicit none
    integer, intent(in) :: d
    integer, intent(inout) :: c(:,:)
    integer :: h, w, i, j
    h = size(c(:,1))
    w = size(c(1,:))
    if (mod(d,2) == 1) then
      do i = 1, h
        do j = 1, w
          c(i,j) = mod(i+j,2)
        end do
      end do
      return
    end if
    if (mod(d,4) == 2) then
      do i = 1, h
        do j = 1, w
          c(i,j) = mod(i,2)
        end do
      end do
      return
    end if
    call coloring(c(1:h:2,1:w:2),d/4)
    call coloring(c(2:h:2,1:w:2),d/4)
    call coloring(c(1:h:2,2:w:2),d/4)
    call coloring(c(2:h:2,2:w:2),d/4)
    return
  end subroutine coloring
end program choosing_points