program ants_on_a_circle
  implicit none
  integer :: n, w, i, j, k, a, b
  integer :: l, t, x(100000), y
  integer :: ccw(100000,2), cw(100000,2)
  integer :: coll, rsdl
  x = 0
  ccw = 0
  cw = 0
  read(*,*) n, l, t
  j = 0
  k = 0
  do i = 1, n
    read(*,*) x(i), w
    if (w.eq.1) then
      j = j+1
      ccw(j,1) = i
      ccw(j,2) = x(i)
    else
      k = k+1
      cw(k,1) = i
      cw(k,2) = x(i)
    end if
  end do
  a = j
  b = k
  if (a.eq.0) then
    t = mod(t,l)
    do i = 1, n
      write(*,'(i0)') mod(x(i)+(l-t),l)
    end do
    stop
  end if
  if (b.eq.0) then
    t = mod(t,l)
    do i = 1, n
      write(*,'(i0)') mod(x(i)+t,l)
    end do
    stop
  end if
  !反時計の蟻の静止系に変換
  !速さを半分にする代わりに時間を倍にする
  t = 2*t
  do j = 1, a
    ccw(j,2) = ccw(j,2)-cw(1,2)
    if (ccw(j,2).lt.0) ccw(j,2) = ccw(j,2)+l
  end do
  call merge_sort(ccw(1:a,:),2)
  ccw(a+1,2) = l
  rsdl = mod(t,l)
  j = 0
  do while ((j.le.a).and.(rsdl.lt.ccw(j+1,2)))
    j = j+1
  end do
  coll = (t/l)*a+j
  do j = 1, a
    ccw(j,2) = x(ccw(j,1))
  end do
  i = cw(1,1)
  cw(1:b,2) = mod(cw(1:b,2)+rsdl,l)
  cw(b+1:n,:) = ccw(1:a,:)
  call merge_sort(cw(1:n,:),2)
  do k = 1, n
    if (cw(k,1).eq.i) then
      j = k
      exit
    end if
  end do
  do k = j, n
    cw(k,1) = i+coll+k-j
    if (cw(k,1).gt.n) cw(k,1) = cw(k,1)-n
  end do
  do k = 1, j-1
    cw(k,1) = i+coll+n+k-j
    if (cw(k,1).gt.n) cw(k,1) = cw(k,1)-n
  end do
  !元の系に戻す
  t = mod(t/2,l)
  do k = 1, n
    i = cw(k,1)
    x(i) = mod(cw(k,2)+(l-t),l)
  end do
  do i = 1, n
    write(*,'(i0)') x(i)
  end do
  stop
contains
subroutine merge_sort(a,j)
    implicit none
    integer, intent(inout) :: a(:,:)
    integer, intent(in) :: j
    integer :: n, m, l, i, u
    n = size(a(:,1))
    m = n
    l = 1
    do while (m.gt.1)
      do i = 1, m/2
        u = min(2*i*l,n)
        call merger(a(2*(i-1)*l+1:(2*i-1)*l,:),a((2*i-1)*l+1:u,:),j)
      end do
      l = 2*l
      m = (m+1)/2
    end do
    return
  end subroutine merge_sort
  subroutine merger(a1,a2,j)
    implicit none
    integer, intent(inout) :: a1(:,:), a2(:,:)
    integer, intent(in) :: j
    integer :: a(size(a1(:,1))+size(a2(:,1)),size(a1(1,:)))
    integer :: i1, i2, n1, n2
    i1 = 1
    i2 = 1
    n1 = size(a1(:,1))
    n2 = size(a2(:,1))
    do while (i1.le.n1.and.i2.le.n2)
      if (a1(i1,j).le.a2(i2,j)) then
        a(i1+i2-1,:) = a1(i1,:)
        i1 = i1+1
      else
        a(i1+i2-1,:) = a2(i2,:)
        i2 = i2+1
       end if
    end do
    if (i1.le.n1) then
      a(i1+i2-1:n1+n2,:) = a1(i1:n1,:)
    else if (i2.le.n2) then
      a(i1+i2-1:n1+n2,:) = a2(i2:n2,:)
    end if
    a1 = a(1:n1,:)
    a2 = a(n1+1:n1+n2,:)
    return
  end subroutine merger
end program ants_on_a_circle