Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {

	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	args := strings.Split(sc.Text(), " ")
	n, _ := strconv.Atoi(args[0])
	t, _ := strconv.ParseInt(args[1], 10, 64)

	q, _ := strconv.Atoi(args[2])

	pos := make([]int64, n)
	direction := make([]bool, n)

	for i := 0; i < n; i++ {
		sc.Scan()
		args = strings.Split(sc.Text(), " ")

		pos[i], _ = strconv.ParseInt(args[0], 10, 64)
		q, _ := strconv.Atoi(args[1])
		if q == 1 {
			direction[i] = true
		}
	}

	qq := make([]int, q)
	for i := 0; i < q; i++ {
		sc.Scan()
		args = strings.Split(sc.Text(), " ")

		qq[i], _ = strconv.Atoi(args[0])
	}

	ans(n, q, t, pos, direction, qq)

}

func ans(n, q int, t int64, pos []int64, dir []bool, qq []int) {

	colleation := []int64{} // syoutotu positon

	for i := 1; i < n; i++ {
		if dir[i-1] == dir[i] {
			continue
		}
		colleation = append(colleation, (pos[i-1]+pos[i])/2)

	}
	//fmt.Println(colleation)
	for i := 0; i < q; i++ {
		var ans int64
		ans = int64(-9999999)
		if dir[qq[i]-1] == true {
			// 東向きなら現ポジから＋方向で一番近い衝突点との距離を求めて、Tとの差が
			for _, v := range colleation {
				if v <= pos[qq[i]-1] {
					continue
				} else {
					// 衝突予定点が確定。衝突点との距離がT以下なら衝突点で停止
					if v-pos[qq[i]-1] <= t {
						ans = v
					} else {
						ans = pos[qq[i]-1] + int64(t)
					}
					break
				}
			}
			if ans == -9999999 {
				ans = pos[qq[i]-1] + int64((t))
			}

		} else {
			// nishi向きなら現ポジから-方向で一番近い衝突点との距離を求めて、Tとの差が
			for j := len(colleation); j > 0; j-- {
				if colleation[j-1] >= pos[qq[i]-1] {
					continue
				}
				v := colleation[j-1]
				//fmt.Printf("hoge=%d\n", v)
				// 衝突予定点が確定
				if pos[qq[i]-1]-v <= t {
					ans = v
				} else {
					ans = pos[qq[i]-1] - int64((t))
				}
				break

			}
			if ans == -9999999 {
				ans = pos[qq[i]-1] - int64((t))
			}

		}
		fmt.Printf("%d\n", ans)

	}

}

Python: n, t, q = map(int, input().split())
x = [[0, 0, 0] for _ in range(n)]
s = -10e30
for i in range(n):
    x[i] = list(map(int, input().split())) + [0]
    x[i][2] = x[i][0] + (1 if x[i][1] == 1 else -1) * t
    if x[i - 1][1] == 1 and x[i][1] == 2:
        s = int((x[i - 1][0] + x[i][0]) / 2)
        j = 1
        while x[i - j][2] > s and x[i - j][1] == 1:
            x[i - j][2] = s
            j += 1
    if x[i][1] == 2:
        x[i][2] = max(x[i][2], s)
for _ in range(q):
    print(x[int(input()) - 1][2])

Python: n, t, q = map(int, input().split())
x = [[0, 0, 0] for _ in range(n)]
s = -10e100
for i in range(n):
    x[i] = list(map(int, input().split())) + [0]
    x[i][2] = x[i][0] + (1 if x[i][1] == 1 else -1) * t
    if x[i - 1][1] == 1 and x[i][1] == 2:
        s = int((x[i - 1][0] + x[i][0]) / 2)
        j = 1
        while x[i - j][2] > s and x[i - j][1] == 1:
            x[i - j][2] = s
            j += 1
    if x[i][1] == 2:
        x[i][2] = max(x[i][2], s)
for _ in range(q):
    print(x[int(input()) - 1][2])

Python: import sys
readline = sys.stdin.readline
write = sys.stdout.write

N, T, Q = map(int, readline().split())
P = [list(map(int, readline().split())) for i in range(N)]
QS = [P[int(readline())-1] for i in range(Q)]
prv = 1
R = {}
A = []; B = []
for x, t in P:
    if prv == t:
        if t == 1:
            A.append(x)
        else:
            B.append(x)
    else:
        if prv == 2:
            y = ((A[-1] if A else -10**19) + (B[0] if B else 10**19)) >> 1
            for z in A:
                R[z] = min(z+T, y)
            for z in B:
                R[z] = max(z-T, y)
            A = [x]; B = []
        else:
            B.append(x)
    prv = t
if A or B:
    y = ((A[-1] if A else -10**19) + (B[0] if B else 10**19)) >> 1
    for z in A:
        R[z] = min(z+T, y)
    for z in B:
        R[z] = max(z-T, y)

for x in QS:
    write("%d\n" % R[x[0]])

Python: n, t, q = map(int, input().split())
x = [[0, 0, 0] for _ in range(n)]
s = -10e40
for i in range(n):
    x[i] = list(map(int, input().split())) + [0]
    x[i][2] = x[i][0] + (1 if x[i][1] == 1 else -1) * t
    if x[i - 1][1] == 1 and x[i][1] == 2:
        s = int((x[i - 1][0] + x[i][0]) / 2)
        j = 1
        while x[i - j][2] > s and x[i - j][1] == 1:
            x[i - j][2] = s
            j += 1
    if x[i][1] == 2:
        x[i][2] = max(x[i][2], s)
for _ in range(q):
    print(x[int(input()) - 1][2])

Python: n, t, q = map(int, input().split())
x = [[0, 0, 0] for _ in range(n)]
s = -10e10
for i in range(n):
    x[i] = list(map(long, input().split())) + [0]
    x[i][2] = x[i][0] + (1 if x[i][1] == 1 else -1) * t
    if x[i - 1][1] == 1 and x[i][1] == 2:
        s = int((x[i - 1][0] + x[i][0]) / 2)
        j = 1
        while x[i - j][2] > s and x[i - j][1] == 1:
            x[i - j][2] = s
            j += 1
    if x[i][1] == 2:
        x[i][2] = max(x[i][2], s)
print(x)
for _ in range(q):
    print(x[int(input()) - 1][2])

Python: n, t, q = map(int, input().split())
x = [[0, 0, 0] for _ in range(n)]
s = -float("inf")
for i in range(n):
    x[i] = list(map(int, input().split())) + [0]
    x[i][2] = x[i][0] + (1 if x[i][1] == 1 else -1) * t
    if x[i - 1][1] == 1 and x[i][1] == 2:
        s = int((x[i - 1][0] + x[i][0]) / 2)
        j = 1
        while x[i - j][2] > s and x[i - j][1] == 1:
            x[i - j][2] = s
            j += 1
    if x[i][1] == 2:
        x[i][2] = max(x[i][2], s)
for _ in range(q):
    print(x[int(input()) - 1][2])

Python: n, t, q = map(int, input().split())
x = [[0, 0, 0] for _ in range(n)]
s = -10e30
for i in range(n):
    x[i] = list(map(int, input().split())) + [0]
    x[i][2] = x[i][0] + (1 if x[i][1] == 1 else -1) * t
    if x[i - 1][1] == 1 and x[i][1] == 2:
        s = int((x[i - 1][0] + x[i][0]) / 2)
        j = 1
        while x[i - j][2] > s and x[i - j][1] == 1:
            x[i - j][2] = s
            j += 1
    if x[i][1] == 2:
        x[i][2] = max(x[i][2], s)
print(x)
for _ in range(q):
    print(x[int(input()) - 1][2])

Python: #D
import bisect
N,T,Q = map(int,input().split())
AD = [list(map(int,input().split())) for i in range(N)]
X = [int(input()) for i in range(Q)]

wall = []
for i in range(N-1):
    a1,d1 = AD[i]
    a2,d2 = AD[i+1]
    
    if d1 == 1 and d2 == 2:
        if T > (a2-a1)//2:
            wall.append((a1+a2)//2)
        
wlen = len(wall)
for x in X:
    ind = x-1
    a,d = AD[ind]
    if d == 1:
        bind = bisect.bisect_left(wall,a)
        if bind == wlen:
            print(a+T)
        else:
            wa = wall[bind]
            if wa <= a+T:
                print(wa)
            else:
                print(a+T)
    else:
        bind = bisect.bisect_left(wall,a)-1
        if bind == -1:
            print(a-T)
        else:
            wa = wall[bind]
            if wa >= a-T:
                print(wa)
            else:
                print(a-T)

Python: n, t, q = map(int, input().split())
x = [[0, 0, 0] for _ in range(n)]
s = -10e10
for i in range(n):
    x[i] = list(map(int, input().split())) + [0]
    x[i][2] = x[i][0] + (1 if x[i][1] == 1 else -1) * t
    if x[i - 1][1] == 1 and x[i][1] == 2:
        s = int((x[i - 1][0] + x[i][0]) / 2)
        j = 1
        while x[i - j][2] > s and x[i - j][1] == 1:
            x[i - j][2] = s
            j += 1
    if x[i][1] == 2:
        x[i][2] = max(x[i][2], s)
for _ in range(q):
    print(x[int(input()) - 1][2])