CodeEff/ECCO huggingface dataset:
# Original solution
from bisect import bisect, bisect_left
import sys

n = int(eval(input()))
x = list(map(int, input().split()))
l = int(eval(input()))

def search_1(start):
	return bisect(x, x[start] + l) - 1

route = [[] for _ in range(n)]

i = 0 # 親の位置
for i in range(n - 1):
	if route[i] == []:
		j = search_1(i) # カーソルの位置
		num = 1 # 何日目の場所か
		route[i].append(j)
		if route[j] == []:
			route[j] = (i, num)
		else: # 既に他の親が通っている
			route[i] += route[route[j][0]][route[j][1]:]
			continue
		while j < n - 1:
			j = search_1(j)
			num += 1
			route[i].append(j)
			if route[j] == []:
				route[j] = (i, num)
			else: # 既に他の親が通っている
				route[i] += route[route[j][0]][route[j][1]:]
				break
	else:
		continue

# print(route)

def search_2(start, goal):
	if type(route[start]) == type([]):
		return bisect_left(route[start], goal) + 1
	else:
		return bisect_left(route[route[start][0]][route[start][1]:], goal) + 1

q = int(eval(input()))
for _ in range(q):
	a, b = list(map(int, sys.stdin.readline().strip().split()))
	if a > b:
		a, b = b, a
	print((search_2(a - 1, b - 1)))

# Optimized solution
from bisect import bisect
import sys

n = int(eval(input()))
x = list(map(int, input().split()))
l = int(eval(input()))
q = int(eval(input()))

#r[i][j]: jから(2**i)日で行ける右端
r = [[i for i in range(n)] for _ in range(18)]
for j in range(n):
	r[0][j] = bisect(x, x[j]+l) - 1
for i in range(1, 18):
	for j in range(n):
		r[i][j] = r[i-1][r[i-1][j]]

def search(x, y):
	res = 0
	cur = x
	i = 17
	while True:
		if i == 0 and r[i][cur] >= y:
			return res+1
		if r[i][cur] < y:
			cur = r[i][cur]
			res += 1 << i
			continue
		i -= 1

for _ in range(q):
	a, b = list(map(int, sys.stdin.readline().strip().split()))
	print((search(min(a, b)-1, max(a, b)-1)))
# Original solution
# seishin.py
N = int(input())
*X, = map(int, input().split())
L = int(input())

K = 318

D = {}
j = N-1
for i in range(N-1, -1, -1):
    while j > 0 and X[j] - X[i] > L:
        j -= 1
    D[i, 0] = j
for k in range(K):
    for i in range(N):
        if (i, k) in D and (D[i, k], k) in D:
            D[i, k+1] = D[D[i, k], k]
def solve(a, b):
    if not a < b:
        a, b = b, a
    res = 1
    for k in range(K, -1, -1):
        if D.get((a, k), N) < b:
            a = D[a, k]
            res += 2**k
    return res
Q = int(input())
ans = []
for i in range(Q):
    a, b = map(int, input().split())
    ans.append(solve(a-1, b-1))
print(*ans, sep='\n')


# Optimized solution
# seishin.py
N = int(input())
*X, = map(int, input().split())
L = int(input())

K = 20

D = [[N]*(K+1) for i in range(N)]
j = N-1
for i in range(N-1, -1, -1):
    while j > 0 and X[j] - X[i] > L:
        j -= 1
    D[i][0] = j
for k in range(K):
    for i in range(N):
        if D[i][k] != N:
            D[i][k+1] = D[D[i][k]][k]
def solve(a, b):
    if not a < b:
        a, b = b, a
    res = 1
    for k in range(K, -1, -1):
        if D[a][k] < b:
            a = D[a][k]
            res += 2**k
    return res
Q = int(input())
ans = []
for i in range(Q):
    a, b = map(int, input().split())
    ans.append(solve(a-1, b-1))
print(*ans, sep='\n')
# Original solution
import sys,bisect

input=sys.stdin.readline

N=int(eval(input()))
x=list(map(int,input().split()))
L=int(eval(input()))

doubling=[[-1 for i in range(N)] for j in range(20)]
backdoubling=[[-1 for i in range(N)] for j in range(20)]

for i in range(N):
    npos=x[i]+L
    index=bisect.bisect_right(x,npos)
    doubling[0][i]=index-1

for i in range(1,20):
    for j in range(N):
        doubling[i][j]=doubling[i-1][doubling[i-1][j]]

for i in range(N):
    npos=x[i]-L
    index=bisect.bisect_left(x,npos)
    backdoubling[0][i]=index

for i in range(1,20):
    for j in range(N):
        backdoubling[i][j]=backdoubling[i-1][backdoubling[i-1][j]]

def forward(num,start):
    for i in range(20):
        if num>>i &1==1:
            start=doubling[i][start]
    return start

def back(num,start):
    for i in range(20):
        if num>>i &1==1:
            start=backdoubling[i][start]
    return start


for _ in range(int(eval(input()))):
    a,b=list(map(int,input().split()))
    a-=1;b-=1
    if b>=a:
        s=0
        e=N
        while e-s>1:
            test=(e+s)//2
            if forward(test,a)>=b:
                e=test
            else:
                s=test
        if forward(s,a)>=b:
            print(s)
        else:
            print(e)
    else:
        s=0
        e=N
        while e-s>1:
            test=(e+s)//2
            if b>=back(test,a):
                e=test
            else:
                s=test
        if b>=back(s,a):
            print(s)
        else:
            print(e)

# Optimized solution
import sys,bisect

input=sys.stdin.readline

N=int(eval(input()))
x=list(map(int,input().split()))
L=int(eval(input()))

doubling=[[-1 for i in range(N)] for j in range(20)]

for i in range(N):
    npos=x[i]+L
    index=bisect.bisect_right(x,npos)
    doubling[0][i]=index-1

for i in range(1,20):
    for j in range(N):
        doubling[i][j]=doubling[i-1][doubling[i-1][j]]

forward=[[-1 for i in range(N)] for j in range(20)]

for i in range(N):
    forward[0][i]=i

for i in range(1,20):
    for j in range(N):
        forward[i][j]=doubling[i-1][forward[i-1][j]]

for _ in range(int(eval(input()))):
    a,b=list(map(int,input().split()))
    a-=1;b-=1
    if a>b:
        a,b=b,a
    res=0
    for i in range(19,-1,-1):
        if b>forward[i][a]:
            a=doubling[i][a]
            res+=2**i
    print(res)
# Original solution
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import bisect

n = int(readline())
x = list(map(int,readline().split()))
l = int(readline())
q = int(readline())
ab = list(map(int,read().split()))

dbl_l = [[] for _ in range(n)]
dbl_r = [[] for _ in range(n)]
for dbl,xx in zip([dbl_l,dbl_r],[x,x[::-1]]):
    j = 0
    for i in range(n):
        while(j < n-1):
            if(abs(xx[j+1] - xx[i]) > l):
                break
            j += 1
        dbl[i].append(j)

    for i in range(30):
        if(dbl[0][-1] == n-1):
            break
        for j in range(n):
            dbl[j].append(dbl[ dbl[j][i] ][i])

def calc(a,b,dbl):
    if(dbl[a][0] >= b):
        return 1
    ind = bisect.bisect_left(dbl[a],b) - 1
    return 2**ind + calc(dbl[a][ind],b,dbl)

ans = []
it = iter(ab)
for a,b in zip(it,it):
    a -= 1
    b -= 1
    if(a<b):
        ans.append(calc(a,b,dbl_l))
    else:
        a,b = n-1-a,n-1-b
        ans.append(calc(a,b,dbl_r))

print(('\n'.join(map(str,ans))))

# Optimized solution
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import bisect

n = int(readline())
x = list(map(int,readline().split()))
l = int(readline())
q = int(readline())
ab = list(map(int,read().split()))

dbl = [[] for _ in range(n)]
j = 0
for i in range(n):
    while(j < n-1):
        if(abs(x[j+1] - x[i]) > l):
            break
        j += 1
    dbl[i].append(j)

for i in range(30):
    if(dbl[0][-1] == n-1):
        break
    for j in range(n):
        dbl[j].append(dbl[ dbl[j][i] ][i])

def calc(a,b):
    if(dbl[a][0] >= b):
        return 1
    ind = bisect.bisect_left(dbl[a],b) - 1
    return 2**ind + calc(dbl[a][ind],b)

ans = []
it = iter(ab)
for a,b in zip(it,it):
    a -= 1
    b -= 1
    a,b = min(a,b),max(a,b)
    ans.append(calc(a,b))

print(('\n'.join(map(str,ans))))
# Original solution
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    x = LI()
    L = I()
    q = I()
    p = [[] for i in range(n)]
    for i in range(n):
        xi = x[i]
        l = i
        r = n
        while r-l > 1:
            m = (l+r) >> 1
            xm = x[m]
            if xm-xi <= L:
                l = m
            else:
                r = m
        p[i].append(l)
    N = 20
    for j in range(N):
        for i in range(n):
            p[i].append(p[p[i][-1]][-1])
    for i in range(q):
        a,b = LI()
        a -= 1
        b -= 1
        a,b = min(a,b),max(a,b)
        ans = 1
        for j in range(N)[::-1]:
            if p[a][j] < b:
                a = p[a][j]
                ans += 1<<j
        print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


# Optimized solution
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    x = LI()
    f = [[] for i in range(n)]
    l = I()
    for i in range(n):
        xi = x[i]
        j = bisect.bisect_right(x,l+xi)-1
        f[i].append(j)
    h = int(math.log(n,2))+1
    for j in range(h-1):
        for i in range(n):
            f[i].append(f[f[i][j]][j])
    q = I()
    for _ in range(q):
        a,b = LI()
        a -= 1
        b -= 1
        if b < a:
            a,b = b,a
        ans = 0
        for i in range(h)[::-1]:
            if f[a][i] < b:
                a = f[a][i]
                ans += 1<<i
        print((ans+1))
    return

#Solve
if __name__ == "__main__":
    solve()
# Original solution
from bisect import*
r=range
n,*t=list(map(int,open(0).read().split()))
m=2**16
x=t[:n]
d=[[bisect(x,y+t[n])-1for y in x]]+[[0]*n for _ in r(m)]
for i in r(m):
  for j in r(n):
    d[i+1][j]=d[i][d[i][j]]
for a in zip(t[n+2::2],t[n+3::2]):
  a,b=sorted(i-1for i in a)
  c=1
  for i in r(m,-1,-1):
    if d[i][a]<b:
      a=d[i][a]
      c+=2**i
  print(c)

# Optimized solution
from math import*
from bisect import*
r=range
n,*t=list(map(int,open(0).read().split()))
m=int(log(n,2)+1)
x=t[:n]
d=[[bisect(x,y+t[n])-1for y in x]]+[[0]*n for _ in r(m)]
for i in r(m):
  for j in r(n):
    d[i+1][j]=d[i][d[i][j]]
for a in zip(t[n+2::2],t[n+3::2]):
  a,b=sorted(i-1for i in a)
  c=1
  for i in r(m,-1,-1):
    if d[i][a]<b:
      a=d[i][a]
      c+=2**i
  print(c)
# Original solution
import sys
input = sys.stdin.readline
import bisect

n = int(eval(input()))
X = list(map(int, input().split()))
l = int(eval(input()))
U = 17
dp = [[0]*n for _ in range(U+1)]
for i, x in enumerate(X):
  t = bisect.bisect_left(X, x+l)
  dp[0][i] = bisect.bisect_right(X, x+l) - 1
for k in range(U):
  for i in range(n):
    dp[k+1][i] = dp[k][dp[k][i]]
def test(x, a, b):
  for i in range(U, -1, -1):
    if x >> i & 1:
      a = dp[i][a]
  return a >= b
def solve(a, b):
  if a > b:
    a, b = b, a
  ng = 0
  ok = n-1
  while ok - ng > 1:
    mid = (ng + ok) // 2
    if test(mid, a, b):
      ok = mid
    else:
      ng = mid
  print(ok)
q = int(eval(input()))
for _ in range(q):
  a, b = list(map(int, input().split()))
  a -= 1
  b -= 1
  solve(a, b)

# Optimized solution
import sys
input = sys.stdin.readline
import bisect

n = int(eval(input()))
X = list(map(int, input().split()))
l = int(eval(input()))
U = 17
dp = [[0]*n for _ in range(U+1)]
for i, x in enumerate(X):
  t = bisect.bisect_left(X, x+l)
  dp[0][i] = bisect.bisect_right(X, x+l) - 1
for k in range(U):
  for i in range(n):
    dp[k+1][i] = dp[k][dp[k][i]]
q = int(eval(input()))
for _ in range(q):
  a, b = list(map(int, input().split()))
  a -= 1
  b -= 1
  if a > b:
    a, b = b, a
  res = 1
  for k in range(U, -1, -1):
    if dp[k][a] < b:
      a = dp[k][a]
      res += (1<<k)
    if a == b:
      break
  print(res)
# Original solution
from collections import defaultdict
from bisect import bisect
inpl = lambda: list(map(int, input().split()))

N = int(input())
X = inpl()
L = int(input())
Q = int(input())
R = {}

for i in range(N):
    R[(0, i)] = bisect(X, X[i]+L) - 1

for k in range(16):
    for i in range(N):
        R[(k+1, i)] = R[(k, R[(k, i)])]


def reach(a, d):
    O = format(d, "b").zfill(17)[::-1]
    for k in range(16, -1, -1):
        if O[k] == "1":
            a = R[(k, a)]
    return a


def bisearch(a, b):
    a, b = a-1, b-1
    if b < a:
        a, b = b, a
    OK = b-a
    NG = 0

    while abs(OK - NG) > 1:
        mid = (OK+NG)//2
        if reach(a, mid) >= b:
            OK = mid
        else:
            NG = mid
    return OK

print(*[bisearch(*inpl()) for _ in range(Q)], sep="\n")


# Optimized solution
from bisect import bisect
inpl = lambda: list(map(int, input().split()))

N = int(input())
X = inpl()
L = int(input())
Q = int(input())
R = [[0]*(N) for k in range(17)]

for i in range(N):
    R[0][i] = bisect(X, X[i]+L) - 1

for k in range(16):
    for i in range(N):
        R[k+1][i] = R[k][R[k][i]]


def reach(a, d):
    O = format(d, "b").zfill(17)[::-1]
    for k in range(16, -1, -1):
        if O[k] == "1":
            a = R[k][a]
    return a


def bisearch(a, b):
    a, b = a-1, b-1
    if b < a:
        a, b = b, a
    OK = b-a
    NG = 0

    while abs(OK - NG) > 1:
        mid = (OK+NG)//2
        if reach(a, mid) >= b:
            OK = mid
        else:
            NG = mid
    return OK

print(*[bisearch(*inpl()) for _ in range(Q)], sep="\n")
# Original solution
import heapq
N, L, T = list(map(int, input().split()))
X = [0 for i in range(N)]
ant = [[] for i in range(2)]
E = [0 for i in range(N)]
for i in range(N):
    X[i], w = list(map(int, input().split()))
    ant[w-1].append(i)
    if w == 1:
        end = X[i] + T
        end = end % L
    if w == 2:
        end = X[i]-T
        end = end % L
        if end < 0:
            end += L
    E[i] = end
len0 = len(ant[0])
len1 = len(ant[1])
TA = []
for m in range(len0):
    for n in range(len1):
        Y0 = ant[0][m]
        Y1 = ant[1][n]
        sa = X[Y1] - X[Y0]
        if sa < 0:
            sa += L
        gikan = sa / 2.0
        while gikan < T:
            heapq.heappush(TA,(gikan, Y0, Y1))
            gikan += L / 2.0
lastant = [i for i in range(N)]

for i in range(len(TA)):
    time, Y0, Y1 = heapq.heappop(TA)
    a = lastant[Y0]
    b = lastant[Y1]
    lastant[Y0] = b
    lastant[Y1] = a

result = [0 for i in range(N)]
for i in range(N):
    result[lastant[i]] = E[i]
for i in range(N):
    print((result[i]))


# Optimized solution
N, L, T = list(map(int, input().split()))
X = [0 for i in range(N)]
W = [0 for i in range(N)]
E = [0 for i in range(N)]
count = 0
for i in range(N):
    X[i], W[i] = list(map(int, input().split()))
    if W[i] == 1:
        end = X[i] + T
        end = end % L
    if W[i] == 2:
        end = X[i]-T
        end = end % L
        if end < 0:
            end += L
    E[i] = end
    shu = L / 2.0
    if i > 0 and W[i] == 2 and  W[0] == 1:
        sa = X[i] -X[0]
        if sa < 0:
            sa += L
        gikan = sa / 2.0
        count += (T - gikan ) // shu + 1
        if (T - gikan) % shu == 0:
            count -= 1

    if i > 0 and W[i] == 1 and  W[0] == 2:
        sa = X[0] -X[i]
        if sa < 0:
            sa += L
        gikan = sa / 2.0
        count -= (T - gikan ) // shu + 1

#print(E)
count = count % N
if count < 0:
    count += N
count = int(count)
#print(count)
basho = E[0]
E.sort()
ind = E.index(basho)
result = [0 for i in range(N)]
for i in range(N):
    newind = ind + i
    if newind >= N :
        newind -= N
    result[count] = E[newind]
    count += 1
    if count >= N:
        count -= N

for i in range(N):
    print((result[i]))
# Original solution
n, l, t = list(map(int, input().split()))
ants = [tuple(map(int, input().split())) for _ in range(n)]
place = []
clock = []
anticlock = []
for i, (x, w) in enumerate(ants):
    if w == 1:
        place.append((x + t) % l)
        clock.append((i, x))
    else:
        place.append((x - t) % l)
        anticlock.append((i, x))

def dist(x, y):
    if x < y: return y - x
    else: return y - x + l

swap = []
for i, x in clock:
    for j, y in anticlock:
        tmp = t * 2
        d = dist(x, y)
        if tmp > d:
            tmp -= d
            swap.append((d, i, j))
            for c in range(1, tmp // l):
                swap.append((d + c * l, i, j))

swap.sort(reverse=True)
for d, i, j in swap:
    place[i], place[j] = place[j], place[i]
for p in place:
    print(p)

# Optimized solution
n, l, t = list(map(int, input().split()))
ants = [tuple(map(int, input().split())) for _ in range(n)]

def dist(x, y, sign_0):
    if sign_0 == -1:
        x, y = y, x
    if x < y: return y - x
    else: return y - x + l

place = []
for i, (x, w) in enumerate(ants):
    sign = 1 if w == 1 else -1
    place.append((x + t * sign) % l)
    if i == 0:
        num = 0
        x_0 = x
        sign_0 = sign
    elif sign_0 * sign == -1:
        length = 2 * t
        d = dist(x_0, x, sign_0)
        if length > d or (length == d and sign_0 == -1):
            num = (num + sign_0) % n
            length -= d
            num = (num + (length // l) * sign_0) % n
            if length % l == 0 and sign_0 == 1:
                num = (num - 1) % n
    else: continue

place.sort()
i_0 = (place.index((x_0 + t * sign_0) % l) - num) % n
place.count((x_0 + t * sign_0) % l)

for i in range(i_0, n + i_0):
    i = i % n
    print((place[i]))
# Original solution
n,l,T = list(map(int,input().split()))
s = [0 for i in range(n)]
for i in range(n):
    s[i] = list(map(int, input().split()))

def f(w):
    if w == 1:
        return 1
    elif w == 2:
        return -1
    

d=[0 for i in range(n)]
for i in range(n-1):
    d[i] = s[i+1][0] - s[i][0]
d[n-1] = s[0][0] + l - s[n-1][0]

t = 0
dt = 0.5
while t < T:
    t+= dt
    s[0][0] = s[0][0] + f(s[0][1])*dt
    if s[0][0] >= l:
        s[0][0] -= l
    elif s[0][0] < 0:
        s[0][0] += l
        
    for i in range(n):
        if i < n-1:
            d[i] = d[i] + f(s[i+1][1])*dt - f(s[i][1])*dt
            s[i+1][0] = s[i][0] + d[i]
            if s[i+1][0] >= l:
                s[i+1][0] -= l
        else:
            d[n-1] = d[n-1] + f(s[0][1])*dt - f(s[n-1][1])*dt
            
    for i in range(n):
        if d[i] == 0 and i < n-1:
            s[i+1][1], s[i][1] = s[i][1], s[i+1][1]
        elif i == n-1 and d[i] == 0 :
            s[0][1], s[n-1][1] = s[n-1][1], s[0][1]
            
import math
for i in range(n):
    print((math.floor(s[i][0])))
    

# Optimized solution
from math import floor
n,l,t = list(map(int,input().split()))
ants = []
touch = 0

for i in range(n):
    x, w = list(map(int,input().split()))
    if w == 1:
        touch += (x + t) // l
        x1 = (x + t) % l
    else:
        touch += (x - t) // l
        x1 = (x - t) % l
    ants.append(x1)
touch = touch % n
ants.sort()
ants = ants[touch:]+ants[:touch]

for i in range(n):
    print((ants[i]))
# Original solution
from collections import deque

n, l, t = list(map(int, input().split()))
ants = [list(map(int, input().split())) for i in range(n)]
# print(ants)

ants_t = []
count = 0
for ant in ants:
    ant_t = ant
    if ant[1] == 1:
        c, ant_t[0] = divmod(t + ant[0], l)
        # count += c
    else:
        c, ant_t[0] = divmod(-t + ant[0], l)
        # count -= c
    ants_t.append(ant_t)
    count += c
# print(ants_t, count)
ants_d = deque(sorted(ants_t))
# print(ants_d)

# if ants_d[0][1] == 1:
#     ants_d.rotate(count)
# else:
#     ants_d.rotate(-count)
ants_d.rotate(-count)
# print(ants_d)
for ant in ants_d:
    print(( (ant[0]) % l ))


# Optimized solution
from collections import deque

n, l, t = list(map(int, input().split()))
ants = [list(map(int, input().split())) for i in range(n)]

ants_t = [0]*n
count = 0
for i in range(n):
    ant = ants[i]
    if ant[1] == 1:
        c, ant_t = divmod(t + ant[0], l)
    else:
        c, ant_t = divmod(-t + ant[0], l)
    ants_t[i] = ant_t
    count += c
# print(ants_t, count)
ants_d = deque(sorted(ants_t))
# print(ants_d)

ants_d.rotate(-count)
# print(ants_d)
for ant in ants_d:
    print(( (ant) % l ))
# Original solution
#AGC 013 C - Ants on a Circle
N,L,T = list(map(int, input().split()))
X = [0]*N
W = [0]*N
for n in range(N):
    X[n],W[n] = list(map(int, input().split()))

for t in range(T):
    #print('now is ',t)
    for n in range(N):
        if n == N-1:
            if X[N-1]%L == X[0] and W[N-1] == 1 and W[0] == 2:
                W[N-1] = 2
                W[0] =1
                X[0] +=1
            else:
                X[N-1] += (-1)**(W[N-1]+1)
                X[N-1] %= L
                if X[N-1] == X[0]:
                	W[N-1] = 2
                	W[0] = 1
        else:
            if X[n] == X[n+1]:
                W[n] = 2
                W[n+1] = 1
                X[n] += (-1)**(W[n]+1)
                X[n] %= L
            elif (X[n]+1)%L == X[n+1] and W[n] == 1 and W[n+1] == 2:
                W[n] = 2
                W[n+1] =1
                X[n+1] -=1
            else:
                X[n] += (-1)**(W[n]+1)
                X[n] %= L
    #for n in range(N):
        #print(X[n],' ',W[n])
for n in range(N):
    print((X[n]))

# Optimized solution
N,L,T = list(map(int, input().split()))
X = [0]*N
W = [0]*N
for n in range(N):
    X[n],W[n] = list(map(int, input().split()))
index = 0
#after T
for n in range(N):
    X[n] += ((-1)**(W[n]+1))*T
    index += X[n]//L
    X[n] %= L
index %= N
X.sort()
X = X[index:] + X[:index] #No.1 wo hajimeni mottekuru.
for n in range(N):
    print((X[n]))
# Original solution
N, L, T = list(map(int, input().split()))
L *= 2
T *= 2

X = [0] * N
W = [0] * N
for i in range(N):
    X[i], W[i] = list(map(int, input().split()))
    X[i] *= 2
    if W[i] == 2:
        W[i] = -1

# print(X, W)
for t in range(T):
    for i in range(N):
        X[i] = (X[i] + W[i]) % L
    for i in range(N):
        if X[i-1] == X[i]:
            W[i-1] *= -1
            W[i] *= -1
    # print(X, W)

for x in X:
    print((x // 2))


# Optimized solution
N, L, T = list(map(int, input().split()))

s = 0
X = [0] * N
for i in range(N):
    x, w = list(map(int, input().split()))
    if w == 1:
        x += T
    else:
        x -= T
    # xが0点を通る回数を足す
    s += x // L
    X[i] = x % L

X.sort()
for i in range(N):
    print((X[(i+s) % N]))
# Original solution
N, L, T = [int(i) for i in input().split()]

ants = list([[x[0] * 2, x[1]] for x in [[int(i) for i in input().split()] for j in range(N)]])

for i in range(T * 2):
	for j in range(N):
		if ants[j][1] == 1:
			if ants[j][0] == 2 * L - 1:
				ants[j][0] = 0
			else:
				ants[j][0] += 1
			if j == N - 1:
				if ants[0][0] == ants[j][0]:
					ants[0][1] = 1
					ants[j][1] = 2
		else:
			if ants[j][0] == 0:
				ants[j][0] = 2 * L - 1
			else:
				ants[j][0] -= 1
			if j != 0:
				if ants[j - 1][0] == ants[j][0]:
					ants[j - 1][1] = 2
					ants[j][1] = 1

for i in range(N):
	print((ants[i][0] // 2))

# Optimized solution
N, L, T = list(map(int, input().split()))
X = []
W = []
for _ in range(N):
    x, w = list(map(int, input().split()))
    X.append(x)
    if w == 2:
        w = -1
    W.append(w)

C = 0
for i in range(1, N):
    if W[i] != W[0]:
        C += T // (L / 2)
        if W[0] == 1:
            D = X[i] - X[0]
        else:
            D = X[0] + L - X[i]
        if T % (L / 2) * 2 >= D:
            C += 1

for i in range(N):
    X[i] = (X[i] + T * W[i]) % L

x = X[0]

X.sort()

ng = -1
ok = N
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if X[mid] >= x:
        ok = mid
    else:
        ng = mid
if W[0] == 1 and ok < N-1:
    if X[ok] == X[ok+1]:
        ok += 1

start = int((ok - C * W[0]) % N)
for i in X[start:]:
    print(i)
for i in X[:start]:
    print(i)