#P9141. Slayers Come

Slayers Come

Source: Super League of Chinese College Students Algorithm Design 2022, Contest 2 by HDU.

Problem Description

Kayzin has recently become addicted to a game called Slayers Come. The game opens with nn monsters standing in a line, with the ii-th monster having an attack power of aia_i (the amount of damage the monster deals when it launches an attack) and a defense power of bib_i (the amount of damage the monster can mitigate when it takes an attack).

Kayzin has mm skills to learn, with the ii-th skill allowing Kayzin to directly defeat a monster with subscript xix_i. This skill has a death rattle effect, i.e., if monsterximonster_{x_i} is defeated and there is a monster to its left (subscripted xi1x_i-1), monsterximonster_{x_i} will launch an attack with damage axiLia_{x_i}-L_i against monsterxi1monster_{x_i-1}; if there is a monster to its right (subscripted xi+1x_i+1), then monsterximonster_{x_i} also fires an attack with damage axiRia_{x_i}-R_i at monsterxi+1monster_{x_i+1}).

If the damage dealt (Damage value - current monster defense) to the monster by one attack is greater than or equal to 0, the monster is defeated , conversely the attack is invalid. It should be noted that when a monster dies, the death rattle causes a chain reaction, meaning that the monster defeated by the death rattle will then attack the monsters on either side of it.Namely,

  • When Kayzin defeats monsterjmonster_j with the ii-th skill (by direct attack or deathrattle), if j>1j > 1 and ajLibj1a_j-L_i\ge b_{j-1}, then this skill also defeats monsterj1monster_{j-1}
  • When Kayzin defeats monsterjmonster_j with the ii-th skill (by direct attack or deathrattle), if j<nj < n and ajRibj+1a_j-R_i\ge b_{j+1}, then this skill also defeats monsterj+1monster_{j+1}

All monsters, including the defeated monsters, always keep their subscripts constant. The defeated monster will re-generate after the effects of all attacks caused by the current skill end, and the re-generated monster keeps its original attack and defense power unchanged.

Kayzin would like to know how many options for learning skills that make it possible to defeat every monster at least once after releasing all the learned skills. The answer modulo 998244353998244353.

Input

The first line contains an integer T(T100)T(T\le 100) . Then TT test cases follow. For one case,

The first line contains two integer nn (n105)(n\le 10^5) and mm (m105)(m\le 10^5) , nn denotes the total number of monsters, and the subscripts of monsters from left to right are 1n1\sim n. mm denotes the type of skills that kayzin can learn.

The next nn lines lists the attack and defense power of the monsters. The ii-th line has two numbers, aia_i and bib_i (1ai,bi109)(1\le a_i,b_i\le 10^9), aia_i denotes the attack power of the monsterimonster_i, bib_i denotes the defense power of the monsterimonster_i.

The next mm lines lists the target of the skill's attack and the effects of its death rattle. The ii-th line has three numbers, xix_i (1xin)(1\le x_i\le n), LiL_i and RiR_i (109Li,Ri109)(-10^9\le L_i,R_i\le 10^9), xix_i denotes the attack target of the ii-th skill, LiL_i denotes how much the monster defeated by this skill weakens the attack power of the monster to its left, RiR_i the same way.

It is guaranteed that the sum of nn over all test cases doesn't exceed 10510^5 and the sum of mm over all test cases doesn't exceed 10510^5.

Output

Print an integer for each case, indicating the number of options for learning skills that make it possible to defeat all the monsters at least once after releasing all the learned skills, the answer modulo 998244353998244353.

Sample

1
4 3
1 4
2 3
3 2
4 1
1 2 -2
2 2 1
3 1 1
4