n, q = gets.split.map(&:to_i)

s = [[1, n, "1"]]

q.times do
  l, r, d = gets.split
  l = l.to_i
  r = r.to_i

  arr = []
  flag = true
  s.each do |li, ri, di|
    if ri < l || r < li
      arr << [li, ri, di]
      next
    end
    
    if flag && l <= ri
      arr << [li, l - 1, di] if li < l
      arr << [l, r, d]
      flag = false
    end

    if !flag && r < ri
      arr << [r + 1, ri, di]
    end
  end
  s = arr
  
  puts s.map {|l, r, d| d * (r - l + 1) }.join("").to_i % 998_244_353
end

