#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
int x[200000];
int y[200000];
int s[200000];
int a[200000];
int pre_sum[200010];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i] >> s[i];
  }
  pre_sum[0] = 0;
  for (int i = 0; i < n; i++) {
    int l = lower_bound(x, x + i, y[i]) - x;
    long long int z = 0;
    z = 1ll * pre_sum[i] + (x[i] - y[i]) + (pre_sum[i] - pre_sum[l]);
    z = z % MOD;
    pre_sum[i + 1] = z;
    a[i] = (1ll * MOD - pre_sum[i] + pre_sum[i + 1]) % MOD;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 1) {
      ans = (ans + a[i]) % MOD;
    }
  }
  ans = (ans + x[n - 1] + 1) % MOD;
  cout << ans << '\n';
  return 0;
}
