#include <bits/stdc++.h>
using namespace std;
const char nl = '\n';
const int MAX_N = 100011;
const long long INF = (1 << 29) + 123;
const long long MOD = 998244353;
const long double PI = 4 * atan((long double)1);
template <typename T>
bool ckmin(T& a, const T& b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T>
bool ckmax(T& a, const T& b) {
  return b > a ? a = b, 1 : 0;
}
void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
  cerr << H << " ";
  dbg_out(T...);
}
template <typename T>
class SafeVector : public vector<T> {
 public:
  using vector<T>::vector;
  typename vector<T>::reference operator[](size_t n) {
    return vector<T>::at(n);
  }
  typename vector<T>::const_reference operator[](size_t n) const {
    return vector<T>::at(n);
  }
};
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MX = 2e5 + 5;
long long a[MX][3];
vector<long long> x;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 3; j++) cin >> a[i][j];
  for (int i = 0; i < n; i++) x.push_back(a[i][0]);
  long long dp[n];
  for (int i = 0; i < n; i++) dp[i] = 0;
  long long pref[n + 1];
  for (int i = 0; i < n + 1; i++) pref[i] = 0;
  dp[0] = a[0][0] - a[0][1];
  pref[1] = dp[0];
  for (int i = 1; i <= n - 1; i++) {
    int idx = lower_bound(x.begin(), x.end(), a[i][1]) - x.begin();
    dp[i] = ((pref[i] - pref[idx]) % MOD + MOD + a[i][0] - a[i][1]) % MOD;
    pref[i + 1] = (pref[i] + dp[i]) % MOD;
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) ans = ((a[i][2] * dp[i]) % MOD + ans) % MOD;
  cout << (ans + x[n - 1] + 1) % MOD << nl;
  return 0;
}
