object Main extends App {
  import scala.io.StdIn._

  val Array(n, q) = readLine.trim.split(' ').map(_.toInt)
  val currentIncrease = Array.tabulate(n){_ ⇒ 0}
  val initialPower = Array.tabulate(n){_ ⇒ new RelationalUnionFind}
  for (_ ← 0 until q){
    val query = readLine.trim.split(' ').toList
    query match {
      case "IN"::xs ⇒ xs.map(_.toInt) match {
        case a::b::c::Nil ⇒
          assert(initialPower(b - 1).mergeIfNotParadoxical(initialPower(a - 1), currentIncrease(a - 1) - currentIncrease(b - 1) + c))
          currentIncrease(a - 1) += c
          currentIncrease(b - 1) += c
        case _ ⇒ ???
      }
      case "COMPARE"::xs ⇒ xs.map(_.toInt) match {
        case a::b::Nil ⇒
          initialPower(b - 1).differFrom(initialPower(a - 1)) match {
            case Some(d) ⇒ println(d - currentIncrease(a - 1) + currentIncrease(b - 1))
            case None ⇒ println("WARNING")
          }
        case _ ⇒ ???
      }
      case _ ⇒ ???
    }
  }

  class RelationalUnionFind {
    private var mParent: Option[RelationalUnionFind] = None
    private var mDiff: Int = 0
    private var mSize: Int = 1
    def parent: (RelationalUnionFind, Int) = {
      mParent.map(_.parent) match {
        case Some((p, d)) ⇒
          mParent = Some(p)
          mDiff += d
          (p, mDiff)
        case None ⇒ (this, 0)
      }
    }
    def mergeIfNotParadoxical(that: RelationalUnionFind, diff: Int): Boolean = {
      val (thisP, thisDiff) = parent
      val (thatP, thatDiff) = that.parent
      if (thisP != thatP){
        if (thisP.mSize > thatP.mSize){
          thatP.mParent = Some(thisP)
          thatP.mDiff = thisDiff - thatDiff - diff
          thisP.mSize += thatP.mSize
        }else {
          thisP.mParent = Some(thatP)
          thisP.mDiff = thatDiff + diff - thisDiff
          thatP.mSize += thisP.mSize
        }
        true
      }else thisDiff == thatDiff + diff
    }
    def differFrom(that: RelationalUnionFind): Option[Int] = {
      val (thisP, thisDiff) = parent
      val (thatP, thatDiff) = that.parent
      if (thisP == thatP){
        Some(thisDiff - thatDiff)
      }else {
        None
      }
    }
  }
}
