#include <bits/stdc++.h>
using namespace std;
int xv[2005], yv[2005];
set<int> st1;
multiset<int> st2[2005];
int val[2005];
struct Point {
  int x, y, c;
  Point() {}
  Point(int a, int b, int c) : x(a), y(b), c(c) {}
};
bool cmp1(Point x, Point y) { return x.x < y.x; }
bool cmp2(Point x, Point y) { return x.y < y.y; }
Point p[2005], q[2005];
int cnt[2005];
int main() {
  int n, m, L;
  scanf("%d%d%d", &n, &m, &L);
  for (int i = 1; i <= n; i++) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    x++;
    y++;
    p[i] = Point(x, y, z);
    xv[i] = x;
    yv[i] = y;
  }
  sort(xv + 1, xv + n + 1);
  sort(yv + 1, yv + n + 1);
  int sz1 = unique(xv + 1, xv + n + 1) - xv - 1,
      sz2 = unique(yv + 1, yv + n + 1) - yv - 1;
  xv[sz1 + 1] = yv[sz2 + 1] = L + 1;
  for (int i = 1; i <= n; i++) {
    p[i].x = lower_bound(xv + 1, xv + sz1 + 1, p[i].x) - xv;
    p[i].y = lower_bound(yv + 1, yv + sz2 + 1, p[i].y) - yv;
    q[i] = p[i];
  }
  sort(p + 1, p + n + 1, cmp1);
  sort(q + 1, q + n + 1, cmp2);
  long long ans = 0;
  for (int i = 1; i <= sz1; i++) {
    memset(cnt, 0, sizeof(cnt));
    long long s = 0;
    int r1 = n, r2 = n, csz = 0;
    for (int j = sz2; j > 0; j--) {
      while (r1 && q[r1].y >= j) {
        if (q[r1].x <= i) {
          if (!cnt[q[r1].c]) csz++;
          cnt[q[r1].c]++;
        }
        r1--;
      }
      if (csz >= m) {
        while (r2 && q[r2].y >= j) {
          if (q[r2].x > i)
            r2--;
          else if (cnt[q[r2].c] > 1) {
            cnt[q[r2].c]--;
            r2--;
          } else
            break;
        }
        val[j] = q[r2].y;
      } else
        val[j] = sz2 + 1;
      s = (s + (long long)(L + 1 - yv[val[j]]) * (yv[j] - yv[j - 1])) %
          1000000007;
    }
    st1.clear();
    for (int j = 0; j <= m; j++) st2[j].clear();
    for (int j = 1; j <= sz2; j++)
      if (j == sz2 || val[j] != val[j + 1]) st1.insert(j);
    for (int j = 1; j <= n; j++)
      if (p[j].x <= i) st2[p[j].c].insert(p[j].y);
    r1 = 1;
    for (int j = 1; j <= i; j++) {
      ans = (ans + s * (xv[j] - xv[j - 1]) % 1000000007 * (xv[i + 1] - xv[i])) %
            1000000007;
      while (r1 <= n && p[r1].x <= j) {
        multiset<int>::iterator it = st2[p[r1].c].lower_bound(p[r1].y),
                                it2 = it;
        it2++;
        if (it2 != st2[p[r1].c].end() && (*it2) == (*it)) {
          st2[p[r1].c].erase(it);
          r1++;
          continue;
        }
        it2 = it;
        int l;
        if (it2 == st2[p[r1].c].begin())
          l = 1;
        else {
          it2--;
          l = (*it2) + 1;
        }
        int r;
        it2 = it;
        it2++;
        if (it2 == st2[p[r1].c].end())
          r = sz2 + 1;
        else
          r = (*it2);
        st2[p[r1].c].erase(it);
        set<int>::iterator it3 = st1.lower_bound(l), it4 = it3;
        if (val[*it3] >= r) {
          r1++;
          continue;
        }
        if (it4 != st1.begin()) {
          it4--;
          if ((*it4) < l - 1) {
            val[l - 1] = val[*it3];
            st1.insert(l - 1);
          }
        } else if (l > 1) {
          val[l - 1] = val[*it3];
          st1.insert(l - 1);
        }
        int last2 = l - 1;
        for (; it3 != st1.end() && val[*it3] < r; it3 = st1.lower_bound(l)) {
          int cur = (*it3);
          s = (s -
               (long long)(yv[r] - yv[val[cur]]) * (yv[cur] - yv[last2]) %
                   1000000007 +
               1000000007) %
              1000000007;
          st1.erase(it3);
          last2 = cur;
        }
        val[last2] = r;
        st1.insert(last2);
        r1++;
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}
