#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10, mod = 998244353;
int n, x[MAXN], y[MAXN], s[MAXN];
long long f[MAXN], sum[MAXN], ans;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d %d %d", &x[i], &y[i], &s[i]);
  for (int i = 1; i <= n; i++) {
    int k = lower_bound(x + 1, x + i + 1, y[i]) - x;
    f[i] = ((x[i] - y[i] + mod) % mod + sum[i - 1] - sum[k - 1] + mod) % mod;
    sum[i] = (sum[i - 1] + f[i]) % mod;
    if (s[i]) ans = (ans + f[i]) % mod;
  }
  printf("%lld", (ans + x[n] + 1) % mod);
  return 0;
}
