#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 7, mod = 1e9 + 7;
long long ans;
struct node {
  int x, y, c, id;
} s[N];
int n, m, col[N], f[N], tot, L, i, j, k, vis[N], mn[N << 2], len[N << 2],
    mx[N << 2], tag[N << 2], sum[N << 2], head[N], y[N], id[N];
struct List {
  int l[N], r[N];
  void del(int x) {
    r[l[x]] = r[x];
    l[r[x]] = l[x];
  }
} q, nq;
void add(int rt, int v) {
  tag[rt] = max(tag[rt], v);
  sum[rt] = 1LL * len[rt] * v % mod;
  mx[rt] = mn[rt] = v;
}
bool cmpx(node a, node b) { return a.x < b.x; }
bool cmpy(node a, node b) { return a.y < b.y; }
void pushdown(int rt) {
  if (tag[rt])
    add((rt << 1), tag[rt]), add((rt << 1 | 1), tag[rt]), tag[rt] = 0;
}
void update(int rt) {
  sum[rt] = (sum[(rt << 1)] + sum[(rt << 1 | 1)]) % mod;
  mn[rt] = min(mn[(rt << 1)], mn[(rt << 1 | 1)]);
  mx[rt] = max(mx[(rt << 1)], mx[(rt << 1 | 1)]);
}
void build(int rt, int l, int r) {
  tag[rt] = sum[rt] = 0;
  len[rt] = y[r] - y[l - 1];
  if (l == r) return add(rt, f[l]);
  int mid = l + r >> 1;
  build((rt << 1), l, mid);
  build((rt << 1 | 1), mid + 1, r);
  update(rt);
}
void modify(int rt, int l, int r, int pre, int v) {
  if (mn[rt] >= v) return;
  if (mx[rt] <= v && pre <= l) return add(rt, v);
  int mid = l + r >> 1;
  pushdown(rt);
  if (pre <= mid) modify((rt << 1), l, mid, pre, v);
  modify((rt << 1 | 1), mid + 1, r, pre, v);
  update(rt);
}
int main() {
  for (scanf("%d%d%d", &n, &m, &L), i = 1; i <= n; ++i)
    scanf("%d%d%d", &s[i].x, &s[i].y, &s[i].c);
  sort(s + 1, s + n + 1, cmpy);
  for (i = 1; i <= n; ++i)
    nq.l[i] = head[s[i].c], nq.r[head[s[i].c]] = i, head[s[i].c] = i,
    nq.r[i] = n + 1, y[i] = s[i].y, s[i].id = i;
  sort(s + 1, s + n + 1, cmpx);
  s[0].x = s[0].y = -1;
  s[n + 1].x = s[n + 1].y = L;
  y[0] = -1;
  y[n + 1] = L;
  for (int i = 1; i <= n; ++i) {
    if (s[i].x ^ s[i - 1].x) {
      for (memset(vis, 0, sizeof(vis)), memset(col, 0, sizeof(col)), j = i;
           j <= n; ++j)
        col[s[j].id] = s[j].c;
      for (memset(vis, 0, sizeof(vis)), tot = 0, j = k = 1; j <= n; ++j) {
        for (; k <= n && tot < m; ++k)
          if (col[k] && !vis[col[k]]++) ++tot;
        f[j] = (tot < m) ? L : y[k - 1];
        if (col[j] && !--vis[col[j]]) tot--;
      }
      q = nq;
      build(1, 1, n);
      int tot = 0;
      for (j = n; j >= i; --j) {
        ans += (1LL * (y[n] + 1) * L % mod - sum[1]) % mod *
               (s[i].x - s[i - 1].x) % mod * (s[j + 1].x - s[j].x) % mod;
        k = s[j].id;
        modify(1, 1, n, q.l[k] + 1, y[q.r[k]]);
        q.del(k);
      }
      ans = (ans % mod + mod) % mod;
    }
    nq.del(s[i].id);
  }
  printf("%lld\n", ans);
}
