Problem: The only difference between easy and hard versions is constraints.

Polycarp loves to listen to music, so he never leaves the player, even on the way home from the university. Polycarp overcomes the distance from the university to the house in exactly T minutes.

In the player, Polycarp stores n songs, each of which is characterized by two parameters: t_i and g_i, where t_i is the length of the song in minutes (1 ≤ t_i ≤ 15), g_i is its genre (1 ≤ g_i ≤ 3).

Polycarp wants to create such a playlist so that he can listen to music all the time on the way from the university to his home, and at the time of his arrival home, the playlist is over. Polycarp never interrupts songs and always listens to them from beginning to end. Thus, if he started listening to the i-th song, he would spend exactly t_i minutes on its listening. Polycarp also does not like when two songs of the same genre play in a row (i.e. successively/adjacently) or when the songs in his playlist are repeated.

Help Polycarpus count the number of different sequences of songs (their order matters), the total duration is exactly T, such that there are no two consecutive songs of the same genre in them and all the songs in the playlist are different.

Input

The first line of the input contains two integers n and T (1 ≤ n ≤ 15, 1 ≤ T ≤ 225) — the number of songs in the player and the required total duration, respectively.

Next, the n lines contain descriptions of songs: the i-th line contains two integers t_i and g_i (1 ≤ t_i ≤ 15, 1 ≤ g_i ≤ 3) — the duration of the i-th song and its genre, respectively.

Output

Output one integer — the number of different sequences of songs, the total length of exactly T, such that there are no two consecutive songs of the same genre in them and all the songs in the playlist are different. Since the answer may be huge, output it modulo 10^9 + 7 (that is, the remainder when dividing the quantity by 10^9 + 7).

Examples

Input


3 3
1 1
1 2
1 3


Output


6


Input


3 3
1 1
1 1
1 3


Output


2


Input


4 10
5 3
2 1
3 2
5 1


Output


10

Note

In the first example, Polycarp can make any of the 6 possible playlist by rearranging the available songs: [1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2] and [3, 2, 1] (indices of the songs are given).

In the second example, the first and second songs cannot go in succession (since they have the same genre). Thus, Polycarp can create a playlist in one of 2 possible ways: [1, 3, 2] and [2, 3, 1] (indices of the songs are given).

In the third example, Polycarp can make the following playlists: [1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1], [1, 4], [4, 1], [2, 3, 4] and [4, 3, 2] (indices of the songs are given).

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const long long infl = 2e18;
const long long infi = 1e9;
const long long mod = 1000000007;
auto clk = clock();
mt19937_64 rang(
    chrono::high_resolution_clock::now().time_since_epoch().count());
long long rng(long long lim) {
  uniform_int_distribution<long long> uid(0, lim - 1);
  return uid(rang);
}
long long powm(long long a, long long b) {
  long long res = 1;
  a %= mod;
  while (b) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}
const long long N = 55;
long long dp[N][N][N][4];
vector<long long> sg[4];
long long knap[4][N][N * N];
long long fact[N];
long long inpe[N];
long long answ[N][N][N * N];
struct base {
  long double x, y;
  base() { x = y = 0; }
  base(long double _x, long double _y) { x = _x, y = _y; }
  base(long double _x) { x = _x, y = 0; }
  void operator=(long double _x) { x = _x, y = 0; }
  long double real() { return x; }
  long double imag() { return y; }
  base operator+(const base& b) { return base(x + b.x, y + b.y); }
  void operator+=(const base& b) { x += b.x, y += b.y; }
  base operator*(const base& b) {
    return base(x * b.x - y * b.y, x * b.y + y * b.x);
  }
  void operator*=(const base& b) {
    long double p = x * b.x - y * b.y, q = x * b.y + y * b.x;
    x = p, y = q;
  }
  void operator/=(long double k) { x /= k, y /= k; }
  base operator-(const base& b) { return base(x - b.x, y - b.y); }
  void operator-=(const base& b) { x -= b.x, y -= b.y; }
  base conj() { return base(x, -y); }
  base operator/(long double k) { return base(x / k, y / k); }
  void Print() { cerr << x << " + " << y << "i\n"; }
};
long double PI = 2.0 * acosl(0.0);
const long long MAXN = 14;
const long long maxn = (1 << MAXN);
base W[maxn], invW[maxn], P1[maxn], Q1[maxn];
void precompute_powers() {
  for (long long i = 0; i < maxn / 2; i++) {
    long double ang = (2 * PI * i) / maxn;
    long double _cos = cos(ang), _sin = sin(ang);
    W[i] = base(_cos, _sin);
    invW[i] = base(_cos, -_sin);
  }
}
void fft(vector<base>& a, bool invert) {
  long long n = (long long)a.size();
  for (long long i = 1, j = 0; i < n; ++i) {
    long long bit = n >> 1;
    for (; j >= bit; bit >>= 1) j -= bit;
    j += bit;
    if (i < j) swap(a[i], a[j]);
  }
  for (long long len = 2; len <= n; len <<= 1) {
    for (long long i = 0; i < n; i += len) {
      long long ind = 0, add = maxn / len;
      for (long long j = 0; j < len / 2; ++j) {
        base u = a[i + j],
             v = (a[i + j + len / 2] * (invert ? invW[ind] : W[ind]));
        a[i + j] = (u + v);
        a[i + j + len / 2] = (u - v);
        ind += add;
      }
    }
  }
  if (invert)
    for (long long i = 0; i < n; ++i) a[i] /= n;
}
void mul_big_mod(vector<long long>& a, vector<long long>& b, long long mod) {
  long long n1 = a.size(), n2 = b.size();
  long long final_size = a.size() + b.size() - 1;
  long long n = 1;
  while (n < final_size) n <<= 1;
  vector<base> P(n), Q(n);
  long long SQRTMOD = (long long)sqrt(mod) + 10;
  for (long long i = 0; i < n1; i++)
    P[i] = base(a[i] % SQRTMOD, a[i] / SQRTMOD);
  for (long long i = 0; i < n2; i++)
    Q[i] = base(b[i] % SQRTMOD, b[i] / SQRTMOD);
  fft(P, 0);
  fft(Q, 0);
  base A1, A2, B1, B2, X, Y;
  for (long long i = 0; i < n; i++) {
    X = P[i];
    Y = P[(n - i) % n].conj();
    A1 = (X + Y) * base(0.5, 0);
    A2 = (X - Y) * base(0, -0.5);
    X = Q[i];
    Y = Q[(n - i) % n].conj();
    B1 = (X + Y) * base(0.5, 0);
    B2 = (X - Y) * base(0, -0.5);
    P1[i] = A1 * B1 + A2 * B2 * base(0, 1);
    Q1[i] = A1 * B2 + A2 * B1;
  }
  for (long long i = 0; i < n; i++) P[i] = P1[i], Q[i] = Q1[i];
  fft(P, 1);
  fft(Q, 1);
  a.resize(final_size);
  for (long long i = 0; i < final_size; i++) {
    long long x = (long long)(P[i].real() + 0.5);
    long long y = (long long)(P[i].imag() + 0.5) % mod;
    long long z = (long long)(Q[i].real() + 0.5);
    a[i] = (x + ((y * SQRTMOD + z) % mod) * SQRTMOD) % mod;
  }
}
void solve() {
  precompute_powers();
  fact[0] = 1;
  for (long long i = 1; i < N; i++) fact[i] = (fact[i - 1] * i) % mod;
  dp[0][0][0][0] = 1;
  for (long long i = 0; i <= 50; i++)
    for (long long j = 0; j <= 50; j++)
      for (long long k = 0; k <= 50; k++) {
        for (long long l = 0; l <= 3; l++)
          if (l != 1) {
            dp[i + 1][j][k][1] += dp[i][j][k][l];
            dp[i + 1][j][k][1] %= mod;
          }
        for (long long l = 0; l <= 3; l++)
          if (l != 2) {
            dp[i][j + 1][k][2] += dp[i][j][k][l];
            dp[i][j + 1][k][2] %= mod;
          }
        for (long long l = 0; l <= 3; l++)
          if (l != 3) {
            dp[i][j][k + 1][3] += dp[i][j][k][l];
            dp[i][j][k + 1][3] %= mod;
          }
      }
  long long n, t;
  cin >> n >> t;
  for (long long i = 1; i <= n; i++) {
    long long ti, gi;
    cin >> ti >> gi;
    sg[gi].push_back(ti);
  }
  for (long long j = 1; j <= 3; j++) {
    knap[j][0][0] = 1;
    for (long long i : sg[j]) {
      for (long long l = ((long long)sg[j].size()) - 1; l >= 0; l--)
        for (long long k = t - i; k >= 0; k--) {
          knap[j][l + 1][k + i] += knap[j][l][k];
          knap[j][l + 1][k + i] %= mod;
        }
    }
  }
  for (long long i = 1; i <= 3; i++)
    for (long long j = 0; j <= ((long long)sg[i].size()); j++)
      for (long long k = 0; k <= t; k++)
        knap[i][j][k] = (knap[i][j][k] * fact[j]) % mod;
  long long ans = 0;
  if (((long long)sg[1].size()) > ((long long)sg[3].size())) {
    swap(sg[1], sg[3]);
    swap(knap[1], knap[3]);
  }
  if (((long long)sg[2].size()) > ((long long)sg[3].size())) {
    swap(sg[2], sg[3]);
    swap(knap[2], knap[3]);
  }
  vector<long long> ho1(t + 1), ho2(t + 1), res;
  for (long long i = 0; i <= ((long long)sg[1].size()); i++) {
    for (long long j = 0; j <= ((long long)sg[2].size()); j++) {
      ho1.resize(t + 1);
      for (long long k = 0; k <= t; k++) {
        ho1[k] = knap[1][i][k];
        ho2[k] = knap[2][j][k];
      }
      mul_big_mod(ho1, ho2, mod);
      for (long long k = 0; k <= t; k++) answ[i][j][k] = ho1[k];
    }
  }
  for (long long i = 0; i <= ((long long)sg[1].size()); i++) {
    for (long long j = 0; j <= ((long long)sg[2].size()); j++) {
      for (long long k = 0; k <= ((long long)sg[3].size()); k++) {
        for (long long l = 0; l <= t; l++) {
          long long o = t - l;
          long long te =
              dp[i][j][k][0] + dp[i][j][k][1] + dp[i][j][k][2] + dp[i][j][k][3];
          te = (te * answ[i][j][l]) % mod;
          ans = (ans + te * knap[3][k][o]) % mod;
        }
      }
    }
  }
  cout << ans << '\n';
}
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  srand(chrono::high_resolution_clock::now().time_since_epoch().count());
  cout << fixed << setprecision(10);
  long long t = 1;
  for (long long i = 1; i <= t; i++) solve();
  return 0;
}