def wf(d)
	n = d.size
	k = 0
	n.times{|k|
		dk = d[k]
		n.times{|i|
			di = d[i]
			dik = i<k ? di[k] : dk[i]
			lim = i>k ? i : k
			j = n-1
			while j>lim
				di[j] = dik + dk[j] if di[j] > dik + dk[j]
				j -= 1
			end
			while j>i
				di[j] = dik + d[j][k] if di[j] > dik + d[j][k]
				j -= 1
			end
		}
	}
	return
	n.times{|i|
		di = d[i]
		j = i-1
		while j >= 0
			di[j] = d[j][i]
			j -= 1
		end
	}
end

INF = 1000000010

def inittbl(n)
	t = Array.new(n){Array.new(n, INF)}
	n.times{|i| t[i][i] = 0 }
	return t
end

input = eval('[' + readlines.join.tr(" \n", ",,") + "]")

z = -1
n = input[z+=1]
m = input[z+=1]
l = input[z+=1]
d = inittbl(n)
m.times{
	a = input[z+=1] - 1
	b = input[z+=1] - 1
	c = input[z+=1]
	d[a][b] = d[b][a] = c
}
wf(d)
e = inittbl(n)
n.times{|i|
	n.times{|j|
		e[i][j] = 1 if d[i][j] <= l
	}
}
wf(e)
q = input[z+=1]
q.times{
	s = input[z+=1] - 1
	t = input[z+=1] - 1
	puts (e[s][t] >= INF ? -1 : e[s][t] - 1)
}
