#include "bits/stdc++.h"
#define puba push_back
#define mapa make_pair 
#define ff first
#define ss second
#define bend(_x) (_x).begin(), (_x).end()
#define szof(_x) ((int) (_x).size())
#define TASK_NAME "trains"

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
const int MAXN = 105;

int field[MAXN][MAXN];
int dist[MAXN][MAXN];
int n, m, k;

int main() {        
    freopen(TASK_NAME ".in", "r", stdin);
    freopen(TASK_NAME ".out", "w", stdout);

    scanf("%d%d%d", &n, &m, &k);

    for (int i = 0; i < m; ++i) {
        int l, r, p;
        scanf("%d%d%d", &l, &r, &p);
        --l; --r; --p;
        for (int j = l; j < r; ++j) {
            field[p][j] = 1;
        }
    }

    for (int i = 0; i < k; ++i) {
        for (int j = n - 2; j >= 0; --j) {
            if (field[i][j]) {
                dist[i][j] = 0;
            } else {
                dist[i][j] = dist[i][j + 1] + 1;
            }
        }
    }

    int q, s, t;
    //cin >> q;
    scanf("%d", &q);
    for (int iq = 0; iq < q; ++iq) {
        //cin >> s >> t;
        scanf("%d%d", &s, &t);
        --s; --t;

        int pos = s;
        int ans = 0;
        while (pos < t) {
            int best = -1;            
            for (int i = 0; i < k; ++i) {
                if (best < dist[i][pos]) {
                    best = dist[i][pos];                    
                }
            }
            if (best == 0) {
                break;
            }
            ++ans;
            pos += best;
        }
        if (pos >= t) {
            cout << ans << "\n";
        } else {
            cout << "-1\n";
        }
    }

    return 0;
}