#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 50, M = 3e5 + 50;
int gi() {
  char ch = getchar();
  int x = 0, q = 0;
  while (ch < '0' || ch > '9') q = ch == '-' ? 1 : q, ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return q ? -x : x;
}
int n, m, C, a[N], b[N], c[N], w[N], rk[N], tr[N * 2], tot, S, siz, fre, sum;
int val[N], Ans[N], ano[N], sa[N];
struct data {
  int s, t;
  bool operator<(const data &b) const { return s < b.s; }
} v[N], q[N], g[N];
map<int, int> f[M];
set<int> ID;
void update(int x) {
  tr[x] = (tr[(x << 1)] > tr[(x << 1 | 1)] ? tr[(x << 1)] : tr[(x << 1 | 1)]);
  return;
}
void add(int x, int l, int r, int y, int s) {
  if (l == r) {
    val[l] += s, tr[x] += s;
    return;
  }
  int mid = (l + r) >> 1;
  if (y <= mid)
    add((x << 1), l, mid, y, s);
  else
    add((x << 1 | 1), mid + 1, r, y, s);
  return update(x);
}
int query(int x, int l, int r, int ql, int qr) {
  if (ql <= l && r <= qr) return tr[x];
  int mid = (l + r) >> 1, tmp, ans = 0;
  if (ql <= mid)
    tmp = query((x << 1), l, mid, ql, qr), ans = (ans > tmp ? ans : tmp);
  if (qr > mid)
    tmp = query((x << 1 | 1), mid + 1, r, ql, qr),
    ans = (ans > tmp ? ans : tmp);
  return ans;
}
void calc(int x) {
  if (v[x].s > C) return;
  sum = (sum > val[x] + ano[sa[x]] ? sum : val[x] + ano[sa[x]]);
  int id = upper_bound(v + 1, v + n + 1, (data){C - v[x].s}) - v - 1, tmp;
  if (!id) return;
  if (id < x) {
    tmp = query(1, 1, n, 1, id);
    sum = (sum > tmp + val[x] ? sum : tmp + val[x]);
  } else {
    if (x > 1) {
      tmp = query(1, 1, n, 1, x - 1);
      sum = (sum > tmp + val[x] ? sum : tmp + val[x]);
    }
    if (id > x) {
      tmp = query(1, 1, n, x + 1, id);
      sum = (sum > tmp + val[x] ? sum : tmp + val[x]);
    }
  }
  return;
}
void cal(int x, int y) {
  if (v[rk[x]].s + v[rk[y]].s > C) return;
  int s = f[x][y];
  ano[x] = (ano[x] > s + val[rk[y]] ? ano[x] : s + val[rk[y]]);
  ano[y] = (ano[y] > s + val[rk[x]] ? ano[y] : s + val[rk[x]]);
  sum = (sum > val[rk[x]] + val[rk[y]] + s ? sum : val[rk[x]] + val[rk[y]] + s);
  return;
}
int main() {
  cin >> n >> C;
  for (int i = 1; i <= n; ++i) {
    a[i] = gi(), b[i] = gi(), c[i] = gi();
    v[i] = (data){c[i], i};
    g[++tot] = (data){a[i], i};
    g[++tot] = (data){b[i], i};
  }
  sort(v + 1, v + n + 1);
  for (int i = 1; i <= n; ++i) rk[v[i].t] = i, sa[i] = v[i].t;
  sort(g + 1, g + tot + 1);
  cin >> m;
  for (int i = 1; i <= m; ++i) q[i] = (data){gi(), i};
  sort(q + 1, q + m + 1);
  int las = 0, s, x, tt = 1;
  for (int i = 1; i <= tot; ++i) {
    s = g[i].s - las, las = g[i].s;
    if (w[g[i].t]) {
      S ^= g[i].t, --siz;
      if (siz == 0)
        add(1, 1, n, rk[g[i].t], s), calc(rk[g[i].t]);
      else if (siz == 1)
        f[g[i].t][S] += s, f[S][g[i].t] += s, cal(g[i].t, S);
      ID.erase(g[i].t);
    } else {
      ++siz;
      if (siz == 1)
        fre += s;
      else if (siz == 2)
        add(1, 1, n, rk[S], s), calc(rk[S]);
      else if (siz == 3)
        x = *ID.begin(), f[x][S ^ x] += s, f[S ^ x][x] += s, cal(S ^ x, x);
      ID.insert(g[i].t);
      S ^= g[i].t, w[g[i].t] = 1;
    }
    while (tt <= m && fre + sum >= q[tt].s)
      Ans[q[tt].t] = las - fre - sum + q[tt].s, ++tt;
  }
  while (tt <= m) Ans[q[tt].t] = las + q[tt].s - fre - sum, ++tt;
  for (int i = 1; i <= m; ++i) printf("%d\n", Ans[i]);
  return 0;
}
