#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <vector>

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> II;
typedef pair<LL, II> III;
typedef priority_queue<III, vector<III>, greater<>> Queue;
static const LL INF = 1LL << 60;

static const long long MOD = 998244353;
static const size_t MAX_N = 1000001;

struct modll {
	long long x;
	modll() { }
	modll(int _x) : x(_x) { }
	operator int() const { return (int)x; }
	modll operator+(int y) { return (x + y + MOD) % MOD; }
	modll operator+=(int y) { x = (x + y + MOD) % MOD; return *this; }
	modll operator-(int y) { return (x - y + MOD) % MOD; }
	modll operator-=(int y) { x = (x - y + MOD) % MOD; return *this; }
	modll operator*(int y) { return (x * y) % MOD; }
	modll operator*=(int y) { x = (x * y) % MOD; return *this; }
	modll operator/(int y) { return (x * modpow(y, MOD - 2)) % MOD; }
	modll operator/=(int y) { x = (x * modpow(y, MOD - 2)) % MOD; return *this; }
	static modll modinv(int a) { return modpow(a, MOD - 2); }
	static modll modpow(int a, int b) {
		modll x = a, r = 1;
		for (; b; b >>= 1, x *= x) if (b & 1) r *= x;
		return r;
	}
};

modll combination(LL n, LL r) {
	static modll fact[MAX_N + 1], inv[MAX_N + 1];
	if (!fact[0]) {
		fact[0] = 1;
		for (int i = 1; i <= MAX_N; ++i) {
			fact[i] = fact[i - 1] * i;
		}
		inv[MAX_N] = modll::modinv(fact[MAX_N]);
		for (int i = MAX_N; i >= 1; --i) {
			inv[i - 1] = inv[i] * i;
		}
	}
	if (r > n) {
		return 0;
	}
	return (fact[n] * inv[r]) * inv[n - r];
}

void solve(long long N, long long Q, std::vector<long long> &L, std::vector<long long> &R, std::vector<long long> &D) {
	vector<vector<modll>> table(10, vector<modll>(N + 1, 0));
	for (LL i = 1; i <= N; ++i) {
		for (int d = 1; d <= 9; ++d) {
			table[d][i] = table[d][i - 1] * 10 + d;
		}
	}

	set<int> s;
	vector<int> len(N + 1), d(N + 1);
	s.insert(0);
	s.insert(N);
	len[0] = N;
	d[0] = 1;
	modll sum = table[1][N];
	for (LL i = 0; i < Q; ++i) {
		LL ll = L[i];
		LL rr = R[i];
		L[i] = N - 1 - rr;
		R[i] = N - 1 - ll + 1;

		auto it = s.lower_bound(L[i]);
		if (*it > L[i]) {
			auto prev = it;
			--prev;
			int st = *prev;
			int l = len[st];
			int ed = st + l;
			int dd = d[st];
			len[st] = L[i] - st;
			sum -= table[dd][ed];
			sum += table[dd][L[i]];
			if (ed > R[i]) {
				s.insert(R[i]);
				len[R[i]] = ed - R[i];
				d[R[i]] = dd;
				sum += table[dd][ed];
				sum -= table[dd][R[i]];

			}
		}
		while (*it < R[i]) {
			int st = *it;
			int l = len[*it];
			int ed = st + l;
			int dd = d[st];
			it = s.erase(it);
			sum -= table[dd][ed];
			sum += table[dd][st];
			if (st + l <= R[i]) {
				continue;
			}
			s.insert(R[i]);
			len[R[i]] = ed - R[i];
			d[R[i]] = dd;
			sum += table[dd][ed];
			sum -= table[dd][R[i]];
			break;
		}
		s.insert(L[i]);
		len[L[i]] = R[i] - L[i];
		d[L[i]] = D[i];
		sum += table[D[i]][R[i]];
		sum -= table[D[i]][L[i]];

/*
		modll ans = 0;
		for (auto x : s) {
			if (x >= N) break;
			ans += table[d[x]][x + len[x]];
			ans -= table[d[x]][x];
		}
		cout << ans << endl;
*/
		cout << sum << endl;
	}
}

int main() {
    long long N;
	std::cin >> N;
	long long Q;
	std::cin >> Q;
	std::vector<long long> L(Q);
	std::vector<long long> R(Q);
	std::vector<long long> D(Q);
	for (int i = 0; i < Q; i++) {
		std::cin >> L[i]; L[i]--;
		std::cin >> R[i]; R[i]--;
		std::cin >> D[i]; // D[i]--;
	}
	solve(N, Q, L, R, D);
	return 0;
}


Measured memory_bytes: 34408