import java.util.*;
import java.io.*;
import java.util.stream.IntStream;

public class trains_as {
    FastScanner in;
    PrintWriter out;

    class Seg implements Comparable<Seg> {
        int s, t, a;

        public Seg(int s, int t, int a) {
            this.s = s;
            this.t = t;
            this.a = a;
        }

        @Override
        public int compareTo(Seg o) {
            if (a != o.a) {
                return a - o.a;
            }
            return s - o.s;
        }

        @Override
        public String toString() {
            return s + " -> " + t + " @ " + a;
        }
    }

    public void solve() throws IOException {
        int n = in.nextInt();
        int m = in.nextInt();
        int k = in.nextInt();
        Seg[] t = new Seg[m];
        for (int i = 0; i < m; i++) {
            int st = in.nextInt() - 1;
            int tt = in.nextInt() - 1;
            int a = in.nextInt() - 1;
            t[i] = new Seg(st, tt, a);
        }
        Arrays.sort(t);
        ArrayList<Seg> freeAl = new ArrayList<Seg>();
        int cur = 0;
        for (int seat = 0; seat < k; seat++) {
            if (cur >= m || t[cur].a > seat) {
                freeAl.add(new Seg(0, n - 1, seat));
            } else {
                int last = 0;
                while (cur < m && t[cur].a == seat) {
                    if (last < t[cur].s) {
                        freeAl.add(new Seg(last, t[cur].s, seat));
                    }
                    last = t[cur].t;
                    cur++;
                }
                if (last < n - 1) {
                    freeAl.add(new Seg(last, n - 1, seat));
                }
            }
        }

        Seg[] free = freeAl.toArray(new Seg[freeAl.size()]);
        Arrays.sort(free, (x, y) -> x.s - y.s);

        int[] go1 = IntStream.range(0, n).toArray();

        TreeSet<Seg> open = new TreeSet<>((x, y) -> x.t == y.t ? x.a - y.a : x.t - y.t);
        cur = 0;
        for (int i = 0; i < n; i++) {
            while (cur < free.length && free[cur].s <= i) {
                open.add(free[cur]);
                cur++;
            }
            if (open.size() > 0) {
                Seg s = open.last();
                if (s.t > i) {
                    go1[i] = s.t;
                }
            }
        }

        int sz = 1;
        while (1 << sz < n) {
            sz += 1;
        }
        int[][] go = new int[sz + 1][n];
        System.arraycopy(go1, 0, go[0], 0, n);
        for (int i = 1; i <= sz; i++) {
            for (int j = 0; j < n; j++) {
                int u = go[i - 1][j];
                go[i][j] = go[i - 1][u];
            }
        }

        int q = in.nextInt();
        for (int i = 0; i < q; i++) {
            int fr = in.nextInt() - 1;
            int to = in.nextInt() - 1;
            if (go[sz][fr] < to) {
                out.println(-1);
            } else {
                int steps = 0;
                int curK = sz;
                while (go1[fr] < to) {
                    while (go[curK][fr] >= to) {
                        curK--;
                    }
                    steps += 1 << curK;
                    fr = go[curK][fr];
                }
                out.println(steps + 1);
            }
        }
    }

    public void run() {
        try {
            in = new FastScanner(new File("trains.in"));
            out = new PrintWriter(new File("trains.out"));

            solve();

            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
    }

    public static void main(String[] arg) {
        new trains_as().run();
    }
}