package main

import (
	"bufio"
	"io/ioutil"
	"os"
	"strconv"
)

var in *bufio.Scanner
var out *bufio.Writer

var (
	p    int
	ibuf []byte
)

func IsSpace(b byte) bool {
	switch b {
	case ' ', '\t', '\n', '\r':
		return true
	default:
		return false
	}
}

func IsDigit(b byte) bool {
	return '0' <= b && b <= '9'
}

func ReadWord() string {
	for ; p < len(ibuf) && IsSpace(ibuf[p]); p++ {
	}
	buf := make([]byte, 0)
	for ; p < len(ibuf) && !IsSpace(ibuf[p]); p++ {
		buf = append(buf, ibuf[p])
	}
	return string(buf)
}

func ReadInt() int {
	for ; p < len(ibuf) && !IsDigit(ibuf[p]); p++ {
	}
	d := 0
	for ; p < len(ibuf) && IsDigit(ibuf[p]); p++ {
		d = 10*d + int(ibuf[p]-'0')
	}
	return d
}

func ReadInt64() int64 {
	for ; p < len(ibuf) && !IsDigit(ibuf[p]); p++ {
	}
	d := int64(0)
	for ; p < len(ibuf) && IsDigit(ibuf[p]); p++ {
		d = int64(10)*d + int64(ibuf[p]-'0')
	}
	return d
}

func init() {
	p = 0
	ibuf, _ = ioutil.ReadAll(os.Stdin)
}

type Bulb struct {
	row int
	col int
	val int
}

type Garland []Bulb

type Query struct {
	cat int
	at  int
	r1  int
	c1  int
	r2  int
	c2  int
}

var n, m, k, q, na int
var garlands []Garland
var queries []Query
var ask, on []int
var tree [][]int64
var contribution [][]int64

func update(row int, col int, val int64) {
	for r := row; r <= n; r += r & (-r) {
		for c := col; c <= m; c += c & (-c) {
			tree[r][c] += val
		}
	}
}

func query(row int, col int) int64 {
	val := int64(0)
	for r := row; r > 0; r -= r & (-r) {
		for c := col; c > 0; c -= c & (-c) {
			val += tree[r][c]
		}
	}
	return val
}

func sum(r1 int, c1 int, r2 int, c2 int) int64 {
	return query(r2, c2) - query(r1-1, c2) - query(r2, c1-1) + query(r1-1, c1-1)
}

func writeInt(val int, c byte) {
	out.WriteString(strconv.Itoa(val))
	out.WriteByte(c)
}

func writeInt64(val int64, c byte) {
	out.WriteString(strconv.FormatInt(val, 10))
	out.WriteByte(c)
}

func main() {
	out = bufio.NewWriter(os.Stdout)
	defer out.Flush()

	n = ReadInt()
	m = ReadInt()
	k = ReadInt()

	garlands = make([]Garland, k)

	for i := 0; i < k; i++ {
		l := ReadInt()

		garlands[i] = make(Garland, l)
		for j := 0; j < l; j++ {
			row := ReadInt()
			col := ReadInt()
			val := ReadInt()
			garlands[i][j] = Bulb{
				row: row,
				col: col,
				val: val,
			}
		}
	}

	q = ReadInt()
	queries = make([]Query, q)
	na = 0

	for i := 0; i < q; i++ {
		cat := ReadWord()
		if cat == "ASK" {
			queries[i].cat = 1
			queries[i].at = na
			na++
			ask = append(ask, i)
			queries[i].r1 = ReadInt()
			queries[i].c1 = ReadInt()
			queries[i].r2 = ReadInt()
			queries[i].c2 = ReadInt()
		} else {
			queries[i].cat = 0
			queries[i].at = ReadInt()
		}
	}

	tree = make([][]int64, n+1)
	for i := 0; i <= n; i++ {
		tree[i] = make([]int64, m+1)
		for j := 0; j <= m; j++ {
			tree[i][j] = 0
		}
	}

	contribution = make([][]int64, k)

	for i := 0; i < k; i++ {
		l := len(garlands[i])
		for j := 0; j < l; j++ {
			b := garlands[i][j]
			update(b.row, b.col, int64(b.val))
		}

		contribution[i] = make([]int64, na)
		for j := 0; j < na; j++ {
			pos := ask[j]
			contribution[i][j] = sum(queries[pos].r1, queries[pos].c1, queries[pos].r2, queries[pos].c2)
		}

		for j := 0; j < l; j++ {
			b := garlands[i][j]
			update(b.row, b.col, int64(-b.val))
		}
	}

	on := make([]int, k)
	for i := 0; i < k; i++ {
		on[i] = 1
	}

	for i := 0; i < q; i++ {
		at := queries[i].at
		if queries[i].cat == 1 {
			res := int64(0)
			for j := 0; j < k; j++ {
				if on[j] == 1 {
					res += contribution[j][at]
				}
			}
			writeInt64(res, '\n')
		} else {
			on[at-1] ^= 1
		}
	}
}

package main

import (
	"bufio"
	"io/ioutil"
	"os"
	"strconv"
)

type Bulb struct {
	row int
	col int
	val int
}

type Garland []Bulb

type Query struct {
	cat int
	at  int
	r1  int
	c1  int
	r2  int
	c2  int
}

var n, m, k, q, na int
var garlands []Garland
var queries []Query
var ask, on []int
var tree [][]int64
var contribution [][]int64

func update(row int, col int, val int64) {
	for r := row; r <= n; r += r & (-r) {
		for c := col; c <= m; c += c & (-c) {
			tree[r][c] += val
		}
	}
}

func query(row int, col int) int64 {
	val := int64(0)
	for r := row; r > 0; r -= r & (-r) {
		for c := col; c > 0; c -= c & (-c) {
			val += tree[r][c]
		}
	}
	return val
}

func sum(r1 int, c1 int, r2 int, c2 int) int64 {
	return query(r2, c2) - query(r1-1, c2) - query(r2, c1-1) + query(r1-1, c1-1)
}

func main() {
	defer out.Flush()

	readInt(&n)
	readInt(&m)
	readInt(&k)

	garlands = make([]Garland, k)

	var l, row, col, val int
	for i := 0; i < k; i++ {
		read(&l)

		garlands[i] = make(Garland, l)
		for j := 0; j < l; j++ {
			readInt(&row)
			readInt(&col)
			readInt(&val)
			garlands[i][j] = Bulb{
				row: row,
				col: col,
				val: val,
			}
		}
	}

	readInt(&q)
	queries = make([]Query, q)
	na = 0

	var cat string
	for i := 0; i < q; i++ {
		readString(&cat)
		if cat == "ASK" {
			queries[i].cat = 1
			queries[i].at = na
			na++
			ask = append(ask, i)
			readInt(&queries[i].r1)
			readInt(&queries[i].c1)
			readInt(&queries[i].r2)
			readInt(&queries[i].c2)
		} else {
			queries[i].cat = 0
			readInt(&queries[i].at)
		}
	}

	// elapsed := time.Since(start)
	// out.WriteString("read time: " + elapsed.String() + "\n")

	tree = make([][]int64, n+1)
	for i := 0; i <= n; i++ {
		tree[i] = make([]int64, m+1)
		for j := 0; j <= m; j++ {
			tree[i][j] = 0
		}
	}

	contribution = make([][]int64, k)

	for i := 0; i < k; i++ {
		l := len(garlands[i])
		for j := 0; j < l; j++ {
			b := garlands[i][j]
			update(b.row, b.col, int64(b.val))
		}

		contribution[i] = make([]int64, na)
		for j := 0; j < na; j++ {
			pos := ask[j]
			contribution[i][j] = sum(queries[pos].r1, queries[pos].c1, queries[pos].r2, queries[pos].c2)
		}

		for j := 0; j < l; j++ {
			b := garlands[i][j]
			update(b.row, b.col, int64(-b.val))
		}
	}

	on := make([]int, k)
	for i := 0; i < k; i++ {
		on[i] = 1
	}

	for i := 0; i < q; i++ {
		at := queries[i].at
		if queries[i].cat == 1 {
			res := int64(0)
			for j := 0; j < k; j++ {
				if on[j] == 1 {
					res += contribution[j][at]
				}
			}
			writeInt64(res)
			writeByte('\n')
		} else {
			on[at-1] ^= 1
		}
	}
}

// Heap
type Node struct {
	name  int
	value int64
	index int
}

type NodeList []*Node

func (nodes NodeList) Len() int {
	return len(nodes)
}

func (nodes NodeList) Less(i int, j int) bool {
	return nodes[i].value < nodes[j].value
}

func (nodes NodeList) Swap(i int, j int) {
	nodes[i], nodes[j] = nodes[j], nodes[i]
	nodes[i].index = i
	nodes[j].index = j
}

func (nodes *NodeList) Push(x interface{}) {
	node := x.(*Node)
	node.index = len(*nodes)
	*nodes = append(*nodes, node)
}

func (nodes *NodeList) Pop() interface{} {
	s := *nodes
	last := len(s) - 1
	r := s[last]
	*nodes = s[:last]
	r.index = -1
	return r
}

// Sort
type Int64Slice []int64

func (s Int64Slice) Len() int               { return len(s) }
func (s Int64Slice) Less(i int, j int) bool { return s[i] < s[j] }
func (s Int64Slice) Swap(i int, j int)      { s[i], s[j] = s[j], s[i] }

// Input output
var out *bufio.Writer
var iPointer int
var nPointer int
var iBuffer []byte

func init() {
	out = bufio.NewWriter(os.Stdout)
	iPointer = 0
	iBuffer, _ = ioutil.ReadAll(os.Stdin)
	nPointer = len(iBuffer)
}

func isLine(c byte) bool {
	return (c == '\n') || (c == '\r')
}

func isSpace(c byte) bool {
	return (c == ' ') || (c == '\t') || (c == '\n') || (c == '\r')
}

func isDigit(c byte) bool {
	return (c >= '0') && (c <= '9')
}

func readByte(v *byte) bool {
	if iPointer >= nPointer {
		return false
	}
	*v = iBuffer[iPointer]
	iPointer++
	return true
}

func readString(v *string) bool {
	for (iPointer < nPointer) && isSpace(iBuffer[iPointer]) {
		iPointer++
	}
	if iPointer >= nPointer {
		return false
	}
	var a []byte
	for (iPointer < nPointer) && !isSpace(iBuffer[iPointer]) {
		a = append(a, iBuffer[iPointer])
		iPointer++
	}
	*v = string(a)
	return true
}

func readInt(v *int) bool {
	neg := false
	for (iPointer < nPointer) && !isDigit(iBuffer[iPointer]) {
		neg = (iBuffer[iPointer] == '-')
		iPointer++
	}
	if iPointer >= nPointer {
		return false
	}
	var a int
	for (iPointer < nPointer) && isDigit(iBuffer[iPointer]) {
		a = a*10 + int(iBuffer[iPointer]-'0')
		iPointer++
	}
	if neg {
		*v = -a
	} else {
		*v = a
	}
	return true
}

func readInt64(v *int64) bool {
	neg := false
	for (iPointer < nPointer) && !isDigit(iBuffer[iPointer]) {
		neg = (iBuffer[iPointer] == '-')
		iPointer++
	}
	if iPointer >= nPointer {
		return false
	}
	var a int64
	for (iPointer < nPointer) && isDigit(iBuffer[iPointer]) {
		a = a*10 + int64(iBuffer[iPointer]-'0')
		iPointer++
	}
	if neg {
		*v = -a
	} else {
		*v = a
	}
	return true
}

func readFloat64(v *float64) bool {
	neg := false
	for (iPointer < nPointer) && !isDigit(iBuffer[iPointer]) {
		if iBuffer[iPointer] != '.' {
			neg = (iBuffer[iPointer] == '-')
		}
		iPointer++
	}
	if iPointer >= nPointer {
		return false
	}
	var a []byte
	if neg {
		a = append(a, '-')
	}
	if iPointer > 0 && iBuffer[iPointer-1] == '.' {
		a = append(a, '.')
	} else {
		for (iPointer < nPointer) && isDigit(iBuffer[iPointer]) {
			a = append(a, iBuffer[iPointer])
			iPointer++
		}
		if (iPointer < nPointer) && (iBuffer[iPointer] == '.') {
			a = append(a, iBuffer[iPointer])
			iPointer++
		}
	}
	for (iPointer < nPointer) && isDigit(iBuffer[iPointer]) {
		a = append(a, iBuffer[iPointer])
		iPointer++
	}
	var ok error
	*v, ok = strconv.ParseFloat(string(a), 64)
	return ok == nil
}

func readln(v *string) bool {
	for (iPointer < nPointer) && isLine(iBuffer[iPointer]) {
		iPointer++
	}
	if iPointer >= nPointer {
		return false
	}
	var a []byte
	for (iPointer < nPointer) && !isLine(iBuffer[iPointer]) {
		a = append(a, iBuffer[iPointer])
		iPointer++
	}
	*v = string(a)
	for (iPointer < nPointer) && isLine(iBuffer[iPointer]) {
		iPointer++
	}
	return true
}

func read(arg interface{}) bool {
	switch v := arg.(type) {
	case *byte:
		return readByte(v)
	case *string:
		return readString(v)
	case *int:
		return readInt(v)
	case *int64:
		return readInt64(v)
	case *float64:
		return readFloat64(v)
	default:
		return false
	}
}

func writeBool(v bool) {
	if v {
		out.WriteString("true")
	} else {
		out.WriteString("false")
	}
}

func writeByte(v byte) {
	out.WriteByte(v)
}

func writeString(v string) {
	out.WriteString(v)
}

func writeInt(v int) {
	out.WriteString(strconv.Itoa(v))
}

func writeInt64(v int64) {
	out.WriteString(strconv.FormatInt(v, 10))
}

func writeFloat64(v float64) {
	out.WriteString(strconv.FormatFloat(v, 'f', -1, 64))
}

func writeln(args ...interface{}) {
	write(args...)
	out.WriteByte('\n')
}

func write(args ...interface{}) {
	for _, a := range args {
		switch v := a.(type) {
		case bool:
			writeBool(v)
		case byte:
			writeByte(v)
		case rune:
			writeByte(byte(v))
		case string:
			writeString(v)
		case int:
			writeInt(v)
		case int64:
			writeInt64(v)
		case float64:
			writeFloat64(v)
		default:
			out.WriteString("###")
		}
	}
}

package main

import "bufio"
import "strconv"
import "os"

// import "time"

var in *bufio.Scanner
var out *bufio.Writer

func read() int {
	in.Scan()
	b := in.Bytes()
	n := 0
	for _, v := range b {
		n = n*10 + int(v-'0')
	}
	return n
}

type Bulb struct {
	row int
	col int
	val int
}

type Garland []Bulb

type Query struct {
	cat int
	at  int
	r1  int
	c1  int
	r2  int
	c2  int
}

var n, m, k, q, na int
var garlands []Garland
var queries []Query
var ask, on []int
var tree [][]int64
var contribution [][]int64

func update(row int, col int, val int64) {
	for r := row; r <= n; r += r & (-r) {
		for c := col; c <= m; c += c & (-c) {
			tree[r][c] += val
		}
	}
}

func query(row int, col int) int64 {
	val := int64(0)
	for r := row; r > 0; r -= r & (-r) {
		for c := col; c > 0; c -= c & (-c) {
			val += tree[r][c]
		}
	}
	return val
}

func sum(r1 int, c1 int, r2 int, c2 int) int64 {
	return query(r2, c2) - query(r1-1, c2) - query(r2, c1-1) + query(r1-1, c1-1)
}

func main() {
	// start := time.Now()

	in = bufio.NewScanner(os.Stdin)
	out = bufio.NewWriter(os.Stdout)

	in.Split(bufio.ScanWords)
	defer out.Flush()

	n = read()
	m = read()
	k = read()

	garlands = make([]Garland, k)

	for i := 0; i < k; i++ {
		l := read()

		garlands[i] = make(Garland, l)
		for j := 0; j < l; j++ {
			row := read()
			col := read()
			val := read()
			garlands[i][j] = Bulb{
				row: row,
				col: col,
				val: val,
			}
		}
	}

	q = read()
	queries = make([]Query, q)
	na = 0

	for i := 0; i < q; i++ {
		in.Scan()
		cat := in.Text()
		if cat == "ASK" {
			queries[i].cat = 1
			queries[i].at = na
			na++
			ask = append(ask, i)
			queries[i].r1 = read()
			queries[i].c1 = read()
			queries[i].r2 = read()
			queries[i].c2 = read()
		} else {
			queries[i].cat = 0
			queries[i].at = read()
		}
	}

	// elapsed := time.Since(start)
	// out.WriteString("read time: " + elapsed.String() + "\n")

	tree = make([][]int64, n+1)
	for i := 0; i <= n; i++ {
		tree[i] = make([]int64, m+1)
		for j := 0; j <= m; j++ {
			tree[i][j] = 0
		}
	}

	contribution = make([][]int64, k)

	for i := 0; i < k; i++ {
		l := len(garlands[i])
		for j := 0; j < l; j++ {
			b := garlands[i][j]
			update(b.row, b.col, int64(b.val))
		}

		contribution[i] = make([]int64, na)
		for j := 0; j < na; j++ {
			pos := ask[j]
			contribution[i][j] = sum(queries[pos].r1, queries[pos].c1, queries[pos].r2, queries[pos].c2)
		}

		for j := 0; j < l; j++ {
			b := garlands[i][j]
			update(b.row, b.col, int64(-b.val))
		}
	}

	on := make([]int, k)
	for i := 0; i < k; i++ {
		on[i] = 1
	}

	for i := 0; i < q; i++ {
		at := queries[i].at
		if queries[i].cat == 1 {
			res := int64(0)
			for j := 0; j < k; j++ {
				if on[j] == 1 {
					res += contribution[j][at]
				}
			}
			out.WriteString(strconv.FormatInt(res, 10))
			out.WriteByte('\n')
		} else {
			on[at-1] ^= 1
		}
	}

	// elapsed = time.Since(start)
	// out.WriteString("total time: " + elapsed.String() + "\n")
}


package main

import (
  "os"
  "bufio"
  "strconv"
)

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer := bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  n, f := getI(), getI()
  for a := 1; a <= 9; a++ {
    digits := make([]int, n)
    carry := 0
    d := a
    for pos := n - 1; pos >= 0; pos-- {
      x := carry + f * d
      d = x % 10
      digits[pos] = d
      carry = x / 10
    }
    if carry == 0 && digits[0] == a && (n == 1 || digits[1] != 0) {
      for i := 1; i < n; i++ {
        writer.WriteByte('0' + byte(digits[i]))
      }
      writer.WriteByte('0' + byte(digits[0]))
      writer.WriteByte('\n')
      return
    }
  }
  writer.WriteString("Impossible\n")
}

package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
	// "time"
)

func main() {
	// defer func(start time.Time) {
	// 	fmt.Println(time.Since(start))
	// }(time.Now())

	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	p, x := nextInt(), nextInt()
	result, number := make([]int, p), make([]int, p)
	multipleResult, tenPower, nextDigit := 0, 0, 0

	if p==1 {
		if x==1 {
			fmt.Println(1)
		} else {
			fmt.Println("Impossible")
		}
		return
	}

	for digit:=1; digit <= 9; digit++ {
		nextDigit = digit
		tenPower = 0
		index := p - 1
		number[index] = nextDigit
		index--
		for i:=0; i<p-1; i++ {
			multipleResult = nextDigit * x + tenPower
			nextDigit = multipleResult%10
			tenPower = multipleResult/10
			number[index]=nextDigit
			index--
			// fmt.Println(multipleResult, nextDigit, tenPower, number)
		}

		if nextDigit == 0 || digit != (nextDigit*x + tenPower) {
			continue
		}

		if result[0] == 0 {
			result, number = number, result
		} else {
			for i:=0; i<p; i++ {
				switch {
				case number[i]==result[i] :
					continue
				case number[i]<result[i] :
					result, number = number, result
				case number[i]>result[i] :
					break
				}
			}
		}
	}

	if result[0] != 0 {
		printInts(result)
	} else {
		fmt.Println("Impossible")
	}
}

func printInts(ints []int) {
	for i, length:= 0, len(ints); i<length; i++ {
		fmt.Fprint(writer, ints[i])
	}
	fmt.Fprintln(writer)
}

var scanner = bufio.NewScanner(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func next() string {
	if !scanner.Scan() {
		panic("Scan error")
	}
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(next())
	if err != nil {
		panic(err)
	}
	return n
}

package main

import (
  "os"
  "bufio"
  "strconv"
)

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer := bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  n, f := getI(), getI()
  for a := 1; a <= 9; a++ {
    digits := make([]int, n)
    carry := 0
    d := a
    for pos := n - 1; pos >= 0; pos-- {
      x := carry + f * d
      d = x % 10
      digits[pos] = d
      carry = x / 10
    }
    if carry == 0 && digits[0] == a {
      for _, d := range digits {
        writer.WriteByte('0' + byte(d))
      }
      writer.WriteByte('\n')
      return
    }
  }
  writer.WriteString("Impossible\n")
}


package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	for ;t>=1; t-- {
		var s string
		fmt.Scan(&s)
		for i:=0;i<len(s);i+=2{
			fmt.Printf("%c",s[i])
		}
		fmt.Printf("%c\n",s[len(s)-1])
	}
}

package main

import "fmt"

func main() {
    var t int
    fmt.Scan(&t)
    for ;t>0;t--{
        var s string
        fmt.Scan(&s)
        for i:=0;i<len(s);i+=2{
            fmt.Printf("%c",s[i])
        }
        fmt.Printf("%c\n",s[len(s)-1]);
    }
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var n int
var s string

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)

	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &s)

		for j := 0; j < len(s); j++ {
			if j%2 == 0 || j == len(s)-1 {
				fmt.Fprintf(out, "%c", s[j])
			}
		}

		fmt.Fprintln(out)
	}

	out.Flush()
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func main() {
	// STDOUT MUST BE FLUSHED MANUALLY!!!
	defer writer.Flush()

	var a int
	scanf("%d\n", &a)
	// printf("Test found: %v\n", a)

	for i := 0; i < a; i++ {
		var b string
		scanf("%s\n", &b)

		for i := 0; i < len(b); i++ {
			if i%2 == 0 || i == len(b)-1 {
				printf("%c", b[i])
			}
		}
		printf("\n")
	}

}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var n int

	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		var s string
		fmt.Fscan(in, &s)
		if len(s) > 3 {
			var nes string
			for j := 0; j < len(s); j += 2 {
				nes += string(s[j])
			}
			nes += string(s[len(s)-1])
			fmt.Println(nes)
		} else {
			fmt.Println(s)
		}
	}
}

// pythonのほうが楽そう
// 文字列ってことで速度が怖いのでテンプレでいくよ

package main
import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main(){
	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush()
	N := nextInt()
	for i:=0; i<N; i++{
		S := chars(next())
		if len(S) == 2{
			fmt.Fprintln(out, strings.Join(S, ""))
			continue
		}
		ans := []string{S[0]}
		for j:=1; j<len(S)-1; j+=2{
			ans = append(ans, S[j])
		}
		ans = append(ans, S[len(S)-1])
		fmt.Fprintln(out, strings.Join(ans, ""))
	}
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextInts(n int) []int{
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}

func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func chars(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

func Next() string {
	sc.Scan()
	return sc.Text()
}

func NextInt() int {
	i, err := strconv.Atoi(Next())
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	for tt := NextInt(); tt > 0; tt-- {
		s := Next()
		if len(s) <= 2 {
			fmt.Println(s)
		} else {
			var ret string
			ret += s[0 : 2]
			for i := 3; i < len(s); i += 2 {
				ret += string(s[i])
			}
			fmt.Println(ret)
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

func min(a, b int) int {
	return int(math.Min(float64(a), float64(b)))
}

func max(a, b int) int {
	return int(math.Max(float64(a), float64(b)))
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscanf(in, "%v\n", &t)
	for now := 0; now < t;now++ {
		var s string
		fmt.Fscanf(in, "%v\n", &s)
		for i := 0;i < len(s);i+=2 {
			fmt.Fprint(out, string(s[i]))
		}
		fmt.Fprintln(out, string(s[len(s) - 1]))
	}
	return
}

package main
import (
        "fmt"
        "os"
        "bufio"
)

func main(){
    var t int
    in := bufio.NewReader(os.Stdin)
    fmt.Fscanln(in, &t)

    var data string
    for ; t > 0; t-- {
        fmt.Fscanln(in, &data)
        fmt.Printf("%c%c", data[0], data[1])
        for i := 3; i < len(data); i += 2 {
            fmt.Printf("%c", data[i])
        }
        fmt.Println()
    }
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main(){
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()
	var t int
	fmt.Fscan(r,&t)
	for ; t > 0 ; t--{
		var s string
		fmt.Fscan(r,&s)
		//fmt.Printf("ls : %d\n",len(s))
		ls := len(s)/2 + 1
		//fmt.Printf("ls : %d\n",ls)
		for i := 0 ;i < ls ;i++{
			if i == 0 {
				fmt.Fprintf(w,"%c",s[0])
			} else {
				fmt.Fprintf(w,"%c",s[2*i-1])
			}
		}
		fmt.Fprint(w,"\n")
	}
}

package main

import "fmt"

func main(){
	//r := bufio.NewReader(os.Stdin)
	//w := bufio.NewWriter(os.Stdout)
	var t int
	fmt.Scan(&t)
	for ; t > 0 ; t--{
		var s string
		fmt.Scan(&s)
		//fmt.Printf("ls : %d\n",len(s))
		ls := len(s)/2 + 1
		//fmt.Printf("ls : %d\n",ls)
		for i := 0 ;i < ls ;i++{
			if i == 0 {
				fmt.Printf("%c",s[0])
			} else {
				fmt.Printf("%c",s[2*i-1])
			}
		}
		fmt.Println()
	}
}
//func main(){
//	//r := bufio.NewReader(os.Stdin)
//	//w := bufio.NewWriter(os.Stdout)
//	var t int
//	fmt.Scanf("%d",&t)
//	for ; t > 0 ; t--{
//		var s string
//		fmt.Scanf("%s",&s)
//		ls := len(s)/2 + 1
//		//fmt.Printf("ls : %d\n",ls)
//		for i := 0 ;i < ls ;i++{
//			if i == 0 {
//				fmt.Printf("%c",s[0])
//			} else {
//				fmt.Printf("%c",s[2*i-1])
//			}
//		}
//		fmt.Println()
//	}
//}
/*
还有一个问题，就是string不是不可变的吗？为什么Scanf取地址，里面函数就能改变了string了呢
*/
//type Point struct {
//	x,y int
//}
//func main()  {
//	p := Point{1,1}
//	fmt.Println(p)
//	p.Increment()
//	fmt.Println(p)
//}
//
//func (p *Point) Increment(){
//	p.x ++
//	p.y ++
//}

//func f(){
//	defer fmt.Println("sign1")
//	fmt.Println("begin f")
//	panic("asdsadasd")
//}
//
//func main(){
//
//	defer func(){
//		w:=recover()
//		fmt.Printf("%T",w)
//	}()
//	f()
//}

//
//func ceshi(){
//	defer trace("function ceshi")()
//
//	time.Sleep(10*time.Second)
//
//}
//func trace(info string)  func() {
//	start := time.Now()
//
//	log.Print("enter "+ info)
//	return func() {
//		log.Printf("exit %s (%s)",info,time.Since(start))
//	}
//}
//
//func main() {
//	ceshi()
//
//}

//!-

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var (
	tests = 0
)

func main() {
	input()
}

func proc(b string) {
	result := ""
	l := len(b)

	if l < 2 || l % 2 == 1{
		fmt.Println(b)
		return
	}

	for i := 0; i < l/2; i++ {
		if i == 0 {
			result += b[i:i+2]
			continue
		}

		if b[i*2] == b[2*i-1] {
			result += b[2*i+1:2*i+2]
			continue
		}

		fmt.Println(b)
		return
	}

	fmt.Println(result)
}

func input() {
	scanner := bufio.NewScanner(os.Stdin)
	if scanner.Scan() {
		tests = parseInt(scanner.Text())
	}

	for ; tests > 0; tests-- {
		var b string
		if scanner.Scan() {
			b = scanner.Text()
		}

		proc(b)
	}
}

func parseInt(text string) int {
	result, _ := strconv.Atoi(text)
	return result
}

package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
)

func fastGetInt(b []byte) int {
	neg := false
	if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n
	}
	return n
}

//========== Implement Algorithm =======================
func solution(val string) string {
	retVal := val[0:2]
	//fmt.Println(retVal)
	for x := 3; x < len(val); x = x + 2 {
		retVal += string(val[x])
	}
	return retVal
}

func main() {

	scanner := bufio.NewScanner(os.Stdin)

	//================== Variables used ====================
	var num int
	var ret string
	//======================================================

	//============== Get return value from File ============
	if len(os.Args) >= 2 {

		file, err := os.Open(os.Args[1])
		if err != nil {
			log.Fatalf("failed opening file: %s", err)
		}
		scanner = bufio.NewScanner(file)
		defer file.Close()

	}
	scanner.Split(bufio.ScanWords)
	//======================= I/O ==========================
	scanner.Scan()
	num = fastGetInt(scanner.Bytes())
	for x := 0; x < num; x++ {
		scanner.Scan()
		ret = solution(scanner.Text())
		fmt.Println(ret)
	}
	//======================================================

	//==================== OUTPUT ==========================

}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	reader := bufio.NewReader(os.Stdin)

	var t int
	fmt.Fscanf(reader, "%d\n", &t)
	for ; t > 0; t-- {
		var s string
		fmt.Fscanf(reader, "%s\n", &s)

		for i := 0; i < len(s); i += 2 {
			fmt.Printf("%c", s[i])
		}
		fmt.Printf("%c\n", s[len(s)-1])
	}
}

package main

// https://codeforces.com/problemset/problem/1367/A
// A. Short Substrings
// time limit per test
// 2 seconds
// memory limit per test
// 256 megabytes
// input
// standard input
// output
// standard output

// Alice guesses the strings that Bob made for her.

// At first, Bob came up with the secret string a
// consisting of lowercase English letters. The string a has a length of 2 or more characters. Then, from string a he builds a new string b and offers Alice the string b so that she can guess the string a

// .

// Bob builds b
// from a as follows: he writes all the substrings of length 2 of the string a in the order from left to right, and then joins them in the same order into the string b

// .

// For example, if Bob came up with the string a
// ="abac", then all the substrings of length 2 of the string a are: "ab", "ba", "ac". Therefore, the string b

// ="abbaac".

// You are given the string b
// . Help Alice to guess the string a that Bob came up with. It is guaranteed that b

// was built according to the algorithm given above. It can be proved that the answer to the problem is unique.
// Input

// The first line contains a single positive integer t
// (1≤t≤1000) — the number of test cases in the test. Then t

// test cases follow.

// Each test case consists of one line in which the string b
// is written, consisting of lowercase English letters (2≤|b|≤100) — the string Bob came up with, where |b| is the length of the string b. It is guaranteed that b

// was built according to the algorithm given above.
// Output

// Output t
// answers to test cases. Each answer is the secret string a, consisting of lowercase English letters, that Bob came up with.

import (
    "bufio"
    "fmt"
    "os"
)

var (
    bufStdin  = bufio.NewReader(os.Stdin)
    bufStdout = bufio.NewWriter(os.Stdout)
)

func main() {
    defer bufStdout.Flush()

    var t int
    _, _ = fmt.Fscan(bufStdin, &t)

    for i := 0; i < t; i++ {
        var b []byte
        _, _ = fmt.Fscan(bufStdin, &b)

        a := make([]byte, 0, len(b))

        a = append(a, b[0])

        for i := 1; i < len(b)-1; i+=2 {
            a = append(a, b[i])
        }

        a = append(a, b[len(b)-1])

        _, _ = fmt.Fprintf(bufStdout, "%s\n", string(a))
    }
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}
func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	var n int
	fmt.Fscanln(r, &n)
	for i := 0; i < n; i++ {
		var b string
		fmt.Fscan(r, &b)
		a := make([]rune, len(b)/2 + 1)
		for j, e := range b {
			if j%2 == 0 {
				a[j/2] = e
			}
		}
		a[len(a)-1] = rune(b[len(b)-1])
		fmt.Fprintln(w, string(a))
	}
}

package main

import (
	"fmt"
	"io/ioutil"
	"os"
)

// https://codeforces.com/problemset/problem/1367/A
// комментарии к решению
// Как видно из примера и алгоритма из строки:
// bccddaaf
// получается:
// bcdaf
// т.е. все серединные (не первый и не последний) парные символы
// нужно превратить в одиночные. В примере выше это достигается
// путём выбора символов с позиций 1 - 3 - 5 - 7 - 8
func taskSolution(a []byte, t int) string {
	ans := []byte{}
	for i, pos := 0, 0; i < t; i += 1 {
		// find next
		// skip len check, because t value control number count
		for !(a[pos] >= 'a' && a[pos] <= 'z') {
			pos += 1
		}
		// skip len check, because t value control number count
		for a[pos] >= 'a' && a[pos] <= 'z' {
			ans = append(ans, a[pos])
			pos += 2
		}
		ans = append(ans, a[pos-1], '\n')
	}
	// truncate last new-line
	return string(ans[:len(ans)-1])
}

func main() {
	var t int
	if _, err := fmt.Scan(&t); err != nil {
		panic(err)
	}

	inRaw, err := ioutil.ReadAll(os.Stdin)
	if err != nil {
		panic(err)
	}

	fmt.Println(taskSolution(inRaw, t))
}

package main

import (
  "fmt"
)

var N int
func main() {
  fmt.Scan(&N)
  for i := 0; i < N; i++ {
    var s string
    fmt.Scan(&s)
    if len(s) == 2 {
      fmt.Println(s)
    } else {
      for j := 0; j < len(s); j+=2 {
        fmt.Printf("%c", s[j])
        if j == len(s)-2 {
          fmt.Printf("%c", s[len(s)-1])
        }
      }
      fmt.Println()
    }
  }
}

package main

import (
	"fmt"
)

func main() {
	//r := bufio.NewReader(os.Stdin)
	//w := bufio.NewWriter(os.Stdout)
	var t int
	fmt.Scan(&t)
	for ; t > 0; t-- {
		var s string

		fmt.Scan(&s)
		ls := len(s)/2 + 1
		//fmt.Printf("ls : %d\n",ls)
		for i := 0; i < ls; i++ {
			if i == 0 {
				fmt.Printf("%c", s[0])
			} else {
				fmt.Printf("%c", s[2*i-1])
			}
		}
		fmt.Println()
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main(){
	var t int
	var s string
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		fmt.Fscan(in,&s)
		fmt.Printf("%s",string(s[0]))
		for j:=1;j<len(s)-1;j+=2{
			fmt.Printf("%s",string(s[j]))
		}
		fmt.Printf("%s\n",string(s[len(s)-1]))
	}
}

package main

import "fmt"

func main() {
    var n int
    fmt.Scanf("%d\n",&n)
    for i := 0;i < n;i++ {
        var s string
        fmt.Scanf("%s\n",&s)
        //fmt.Print("123")
        l := len(s)
        for j := 0;j < l;j += 2 {
            fmt.Printf("%c",s[j])
        }
        fmt.Printf("%c\n",s[l - 1])
    }
}

package main

import (
 	"fmt"
)

func solve() {
	var str string
	fmt.Scan(&str)
	var res string
	res = res + string(str[0])

	for i := 1; i < len(str); i+=2 {
		res = res + string(str[i])
	}

	fmt.Println(res)
}

func main() {
	var t int
	fmt.Scanf("%d\n", &t)

	for i := 0; i < t; i++ {
		solve()
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"bytes"
)

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input *bufio.Reader

func main() {
	var T int

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscanln(input, &T)
	for i := 0; i < T; i++ {
		solver()
	}
}

func solver() {
	var s string
	fmt.Fscan(input, &s)
	var b bytes.Buffer
	for i := 0; i < len(s); i+=2 {
		b.WriteByte(s[i])
	}
	b.WriteByte(s[len(s)- 1])
	fmt.Println(b.String())
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var b string
		fmt.Fscan(in, &b)
		if len(b) == 1 {
			fmt.Println(b)
		} else {
			a := ""
			for i, ch := range b {
				if i%2 == 0 {
					a += string(ch)
				}
			}
			a += string(b[len(b)-1])
			fmt.Println(a)
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < cases; i++ {
		line := readLine(reader)
		result := make([]byte, 0)
		result = append(result, line[0], line[1])
		for i := 2; i < len(line) ; i=i+2 {
			if line[i] == line[i-1] {
				result = append(result, line[i+1])
			} else {
				result = append(result, line[i], line[i+1])
			}
		}
		fmt.Println(string(result))
	}
}

func readLine(reader *bufio.Reader) []byte {
	result := make([]byte, 0)
	for {
		s, isPrefix, err := reader.ReadLine()
		if err != nil {
			fmt.Printf("error=%+v\n", err)
			break
		}
		result = append(result, s...)
		if !isPrefix {
			break
		}
	}
	return result
}

package main
import (
        "fmt"
        "os"
        "bufio"
)

func main(){
    var t int
    in := bufio.NewReader(os.Stdin)
    fmt.Fscanln(in, &t)
    var data string
    for ; t > 0; t-- {
        fmt.Fscanln(in, &data)
        fmt.Println(len(data))
        fmt.Printf("%c%c", data[0], data[1])
        for i := 3; i < len(data); i += 2 {
            fmt.Printf("%c", data[i])
        }
        fmt.Println()
    }
}

package main

import "fmt"

func main(){
	//r := bufio.NewReader(os.Stdin)
	//w := bufio.NewWriter(os.Stdout)
	var t int
	fmt.Scan(&t)
	for ; t > 0 ; t--{
		var s string
		fmt.Scan(&s)
		fmt.Printf("ls : %d\n",len(s))
		ls := len(s)/2 + 1
		//fmt.Printf("ls : %d\n",ls)
		for i := 0 ;i < ls ;i++{
			if i == 0 {
				fmt.Printf("%c",s[0])
			} else {
				fmt.Printf("%c",s[2*i-1])
			}
		}
		fmt.Println()
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var (
	tests = 0
)

func main() {
	input()
}

func process(b string) {
	result := ""

	if len(b) < 2 {
		fmt.Println(b)
		return
	}

	if len(b) == 2 {
		if b[0] == b[1] {
			fmt.Println(b[:1])
			return
		}

		fmt.Println(b)
		return
	}

	newB := b[:1] + b + b[len(b)-1:]
	check := true
	for i := 0; i < len(newB); i++ {
		if i < 1 || i > len(b) {
			continue
		}

		if i%2==1 && newB[i] != newB[i-1] {
			check = false
			break
		}
	}

	if !check {
		fmt.Println(b)
		return
	}

	for i, _ := range b {
		if i < 1 {
			result += string(b[i])
			continue
		}

		if b[i] != b[i-1] {
			result += string(b[i])
			continue
		}

		b = b[:i] + "0" + b[i+1:]
	}

	fmt.Println(result)
}

func input() {
	scanner := bufio.NewScanner(os.Stdin)
	if scanner.Scan() {
		tests = parseInt(scanner.Text())
	}

	for ; tests > 0; tests-- {
		var b string
		if scanner.Scan() {
			b = scanner.Text()
		}

		process(b)
	}
}

func parseInt(text string) int {
	result, _ := strconv.Atoi(text)
	return result
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var (
	tests = 0
)

func main() {
	input()
}

func proc(b string) {
	result := ""
	l := len(b)

	if l < 2 {
		fmt.Println(b)
		return
	}

	for i := 0; i < l/2; i++ {
		if i == 0 {
			result += b[i:i+2]
			continue
		}

		if b[i] == b[i-1] {
			result += b[i+1:i+2]
			continue
		}

		fmt.Println(b)
		return
	}

	fmt.Println(result)
}

func input() {
	scanner := bufio.NewScanner(os.Stdin)
	if scanner.Scan() {
		tests = parseInt(scanner.Text())
	}

	for ; tests > 0; tests-- {
		var b string
		if scanner.Scan() {
			b = scanner.Text()
		}

		proc(b)
	}
}

func parseInt(text string) int {
	result, _ := strconv.Atoi(text)
	return result
}

package main

import "fmt"

func main() {
    var n int
    fmt.Scanf("%d",&n)
    for i := 0;i < n;i++ {
        var s string
        fmt.Scanf("%s\n",&s)
        //fmt.Print("123")
        l := len(s)
        for j := 0;j < l;j++ {
            fmt.Printf("%c",s[j])
            if j < l - 1 && s[j] == s[j + 1] {
                j++
            }
        }
        fmt.Println("")
    }
}

package main

import "fmt"

func main() {
    var n int
    fmt.Scanf("%d",&n)
    for i := 0;i < n;i++ {
        var s string
        fmt.Scanf("%s",&s)
        l := len(s)
        for j := 0;j < l;j++ {
            fmt.Printf("%c",s[j])
            if j < l - 1 && s[j] == s[j + 1] {
                j++
            }
        }
        fmt.Println("")
    }
}

package main

import "fmt"

func main() {
    var n int
    fmt.Scanf("%d\n",&n)
    for i := 0;i < n;i++ {
        var s string
        fmt.Scanf("%s\n",&s)
        //fmt.Print("123")
        l := len(s)
        for j := 0;j < l;j++ {
            fmt.Printf("%c",s[j])
            if j < l - 1 && s[j] == s[j + 1] {
                j++
            }
        }
        fmt.Println("")
    }
}

package main

import "fmt"

func main() {
    var n int
    fmt.Scanf("%d",&n)
    for i := 0;i < n;i++ {
        var s string
        fmt.Scanf("%s",&s)
        l := len(s)
        for j := 0;j < l;j++ {
            fmt.Printf("%c",s[j])
            if j < l - 1 && s[j] == s[j + 1] {
                j++
            }
        }
        fmt.Printf("\n")
    }
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var n int

	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		var s string
		fmt.Fscan(in, &s)
		if len(s) > 5 {
			var nes string
			for j := 0; j < len(s); j += 2 {
				nes += string(s[j])
			}
			nes += string(s[len(s)-1])
			fmt.Println(nes)
		} else {
			fmt.Println(s)
		}
	}
}


package main

import (
	"bufio"
	. "fmt"
	"io"
	"math"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func CF1033D(_r io.Reader, _w io.Writer) {
	const mod int64 = 998244353
	sqrt := func(a int64) int64 {
		r := int64(math.Round(math.Sqrt(float64(a))))
		if r*r == a {
			return r
		}
		return -1
	}
	cbrt := func(a int64) int64 {
		r := int64(math.Round(math.Cbrt(float64(a))))
		if r*r*r == a {
			return r
		}
		return -1
	}
	gcd := func(a, b int64) int64 {
		for a != 0 {
			a, b = b%a, a
		}
		return b
	}

	in := bufio.NewReader(_r)
	var n int
	Fscan(in, &n)
	a := make([]int64, 0, n)
	vis := make([]bool, 0, n)
	cntv := map[int64]int{}
	cnte := map[int64]int{}
	for ; n > 0; n-- {
		var v int64
		Fscan(in, &v)
		ok := true
		if r := cbrt(v); r != -1 {
			cnte[r] += 3
		} else if r := sqrt(v); r != -1 {
			if r4 := sqrt(r); r4 != -1 {
				cnte[r4] += 4
			} else {
				cnte[r] += 2
			}
		} else {
			ok = false
		}
		cntv[v]++
		if cntv[v] == 1 {
			a = append(a, v)
			vis = append(vis, ok)
		}
	}

	ans := int64(1)
	for i, x := range a {
		if !vis[i] {
			for j, y := range a {
				if j == i {
					continue
				}
				if g := gcd(x, y); g > 1 {
					cnte[g] += cntv[x]
					cnte[x/g] += cntv[x]
					if !vis[j] {
						cnte[g] += cntv[y]
						cnte[y/g] += cntv[y]
						vis[j] = true
					}
					vis[i] = true
					break
				}
			}
		}
		if !vis[i] {
			c := cntv[x] + 1
			ans = ans * int64(c*c) % mod
		}
	}
	for _, e := range cnte {
		ans = ans * int64(e+1) % mod
	}
	Fprintln(_w, ans)
}

func main() { CF1033D(os.Stdin, os.Stdout) }

package main

import (
	"fmt"
)

func gcd(a, b uint64) uint64 {
	if a % b == 0 {
		return b
	} else {
		return gcd(b, a % b)
	}
}

func cubeRoot(a, left, right uint64) (uint64, bool) {
	if left > right {
		return 0, false
	}
	mid := (left + right) / 2
	ans := mid * mid * mid
	if ans == a {
		return mid, true
	} else if ans > a {
		return cubeRoot(a, left, mid - 1)
	} else {
		return cubeRoot(a, mid + 1, right)
	}
}

func root(a, left, right uint64) (uint64, bool) {
	if left > right {
		return 0, false
	}
	mid := (left + right) / 2
	ans := mid * mid
	if ans == a {
		return mid, true
	} else if ans > a {
		return root(a, left, mid - 1)
	} else {
		return root(a, mid + 1, right)
	}
}

var	factor map[uint64]int = map[uint64]int{}
func main() {
	var n int
	f4 := make([]uint64, 0, 500)
	fmt.Scanf("%d\n", &n)
	for i := 0;i < n;i ++ {
		var a uint64
		fmt.Scanf("%d\n", &a)
		if ro0, isSq0 := root(a, 1, 1414213563); isSq0 {
			if ro1, isSq1 := root(ro0, 1, 1414213563); isSq1 {
				factor[ro1] += 4
			} else {
				factor[ro0] += 2
			}
		} else if cr, isCr := cubeRoot(a, 1, 1259922); isCr {
			factor[cr] += 3
		} else {
			f4 = append(f4, a)
		}
	}
	for i := 0;i < len(f4);i ++ {
		a := f4[i]
		if a == 1 {
			continue
		}
		var flag bool
		for f, _ := range factor {
			if a % f == 0 {
				factor[f] ++
				factor[a / f] ++
				f4[i] = 1
				flag = true
				break
			}
		}
		if flag {
			continue
		} else {
			for j := i + 1;j < len(f4);j ++ {
				b := f4[j]
				if a == b || b == 1 {
					continue
				}
				if f := gcd(a, b); f != 1 {
					factor[f] += 2
					factor[a / f] ++
					factor[b / f] ++
					f4[i], f4[j] = 1, 1
					break
				}
			}
		}
	}
	var ans uint64 = 1
	for _, count := range factor {
		ans *= uint64(count + 1)
		ans %= 998244353
	}
	fac4 := map[uint64]int{}
	for i := 0;i < len(f4);i ++ {
		if f4[i] != 1 {
			fac4[f4[i]] ++
		}
	}
	for _, count := range fac4 {
		ans *= uint64((count + 1) * (count + 1))
		ans %= 998244353
	}
	fmt.Printf("%d", ans)
}

package main

import (
	"fmt"
	"math"
)

func sqrt(x int64) (int64, bool) {
	st := int64(math.Sqrt(float64(x))) - 100
	if st < 2 {
		st = 2
	}
	for i := st; i*i <= x; i++ {
		if i*i == x {
			return i, true
		}
	}
	return 0, false
}

func cbrt(x int64) (int64, bool) {
	st := int64(math.Pow(float64(x), 1./3)) - 100
	if st < 2 {
		st = 2
	}
	for i := st; i*i*i <= x; i++ {
		if i*i*i == x {
			return i, true
		}
	}
	return 0, false
}

const mod = 998244353

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int64, n)
	var pq []int64
	m := make(map[int64]int64)
	for i := range a {
		fmt.Scan(&a[i])
		if s, ok := sqrt(a[i]); ok {
			if t, ok := sqrt(s); ok {
				m[t] += 4
			} else {
				m[s] += 2
			}
		} else if c, ok := cbrt(a[i]); ok {
			m[c] += 3
		} else {
			pq = append(pq, a[i])
		}
	}

	for i := range pq {
		for p := range m {
			if pq[i]%p == 0 {
				m[pq[i]/p]++
				m[p]++
				pq[i] = 0
				break
			}
		}
		if pq[i] == 0 {
			continue
		}
		for j := i + 1; j < len(pq); j++ {
			if pq[i] == pq[j] {
				continue
			}
			g := gcd(pq[i], pq[j])
			if g > 1 {
				m[pq[i]/g]++
				m[g]++
				pq[i] = 0
				break
			}
		}
	}

	pqm := make(map[int64]int64)
	for _, pq := range pq {
		if pq != 0 {
			pqm[pq]++
		}
	}

	ans := int64(1)
	for _, n := range pqm {
		ans = (ans * (n + 1) * (n + 1)) % mod
	}

	for _, n := range m {
		ans = (ans * (n + 1)) % mod
	}
	fmt.Println(ans)
}

func gcd(a, b int64) int64 {
	for a != 0 {
		a, b = b%a, a
	}
	return b
}

package main

import (
	"fmt"
	"math"
)

func sqrt(x int64) (int64, bool) {
	st := int64(math.Sqrt(float64(x))) - 100
	if st < 2 {
		st = 2
	}
	for i := st; i*i <= x; i++ {
		if i*i == x {
			return i, true
		}
	}
	return 0, false
}

func cbrt(x int64) (int64, bool) {
	for i := int64(math.Pow(float64(x), 1./3)) - 100; i*i*i <= x; i++ {
		if i*i*i == x {
			return i, true
		}
	}
	return 0, false
}

const mod = 998244353

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int64, n)
	var pq []int64
	m := make(map[int64]int64)
	for i := range a {
		fmt.Scan(&a[i])
		if s, ok := sqrt(a[i]); ok {
			if t, ok := sqrt(s); ok {
				m[t] += 4
			} else {
				m[s] += 2
			}
		} else if c, ok := cbrt(a[i]); ok {
			m[c] += 3
		} else {
			pq = append(pq, a[i])
		}
	}

	for i := range pq {
		for p := range m {
			if pq[i]%p == 0 {
				m[pq[i]/p]++
				m[p]++
				pq[i] = 0
				break
			}
		}
		if pq[i] == 0 {
			continue
		}
		for j := i + 1; j < len(pq); j++ {
			g := gcd(pq[i], pq[j])
			if g > 1 {
				m[pq[i]/g]++
				m[g]++
				pq[i] = 0
				break
			}
		}
	}

	pqm := make(map[int64]int64)
	for _, pq := range pq {
		if pq != 0 {
			pqm[pq]++
		}
	}

	ans := int64(1)
	for _, n := range pqm {
		ans = (ans * (n + 1) * (n + 1)) % mod
	}

	for _, n := range m {
		ans = (ans * (n + 1)) % mod
	}
	fmt.Println(ans)
}

func gcd(a, b int64) int64 {
	for a != 0 {
		a, b = b%a, a
	}
	return b
}

package main

import (
	"fmt"
	"math"
)

func sqrt(x int64) (int64, bool) {
	st := int64(math.Sqrt(float64(x))) - 100
	if st < 2 {
		st = 2
	}
	for i := st; i*i <= x; i++ {
		if i*i == x {
			return i, true
		}
	}
	return 0, false
}

func cbrt(x int64) (int64, bool) {
	st := int64(math.Pow(float64(x), 1./3)) - 100
	if st < 2 {
		st = 2
	}
	for i := st; i*i*i <= x; i++ {
		if i*i*i == x {
			return i, true
		}
	}
	return 0, false
}

const mod = 998244353

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int64, n)
	var pq []int64
	m := make(map[int64]int64)
	for i := range a {
		fmt.Scan(&a[i])
		if s, ok := sqrt(a[i]); ok {
			if t, ok := sqrt(s); ok {
				m[t] += 4
			} else {
				m[s] += 2
			}
		} else if c, ok := cbrt(a[i]); ok {
			m[c] += 3
		} else {
			pq = append(pq, a[i])
		}
	}

	for i := range pq {
		for p := range m {
			if pq[i]%p == 0 {
				m[pq[i]/p]++
				m[p]++
				pq[i] = 0
				break
			}
		}
		if pq[i] == 0 {
			continue
		}
		for j := i + 1; j < len(pq); j++ {
			g := gcd(pq[i], pq[j])
			if g > 1 {
				m[pq[i]/g]++
				m[g]++
				pq[i] = 0
				break
			}
		}
	}

	pqm := make(map[int64]int64)
	for _, pq := range pq {
		if pq != 0 {
			pqm[pq]++
		}
	}

	ans := int64(1)
	for _, n := range pqm {
		ans = (ans * (n + 1) * (n + 1)) % mod
	}

	for _, n := range m {
		ans = (ans * (n + 1)) % mod
	}
	fmt.Println(ans)
}

func gcd(a, b int64) int64 {
	for a != 0 {
		a, b = b%a, a
	}
	return b
}

package main

import (
	"fmt"
)

func gcd(a, b uint64) uint64 {
	if a % b == 0 {
		return b
	} else {
		return gcd(b, a % b)
	}
}

func cubeRoot(a, left, right uint64) (uint64, bool) {
	if left > right {
		return 0, false
	}
	mid := (left + right) / 2
	ans := mid * mid * mid
	if ans == a {
		return mid, true
	} else if ans > a {
		return cubeRoot(a, left, mid - 1)
	} else {
		return cubeRoot(a, mid + 1, right)
	}
}

func root(a, left, right uint64) (uint64, bool) {
	if left > right {
		return 0, false
	}
	mid := (left + right) / 2
	ans := mid * mid
	if ans == a {
		return mid, true
	} else if ans > a {
		return root(a, left, mid - 1)
	} else {
		return root(a, mid + 1, right)
	}
}

var	factor map[uint64]int = map[uint64]int{}
func main() {
	var n int
	f4 := make([]uint64, 0, 500)
	fmt.Scanf("%d\n", &n)
	for i := 0;i < n;i ++ {
		var a uint64
		fmt.Scanf("%d\n", &a)
		if ro0, isSq0 := root(a, 1, 1414213563); isSq0 {
			if ro1, isSq1 := root(ro0, 1, 1414213563); isSq1 {
				factor[ro1] += 4
			} else {
				factor[ro0] += 2
			}
		} else if cr, isCr := cubeRoot(a, 1, 1259922); isCr {
			factor[cr] += 3
		} else {
			f4 = append(f4, a)
		}
	}
	for i := 0;i < len(f4);i ++ {
		a := f4[i]
		if a == 1 {
			continue
		}
		var flag bool
		for f, _ := range factor {
			if a % f == 0 {
				factor[f] ++
				factor[a / f] ++
				f4[i] = 1
				flag = true
				break
			}
		}
		if flag {
			continue
		} else {
			for j := i + 1;j < len(f4);j ++ {
				b := f4[j]
				if f := gcd(a, b); f != 1 {
					factor[f] += 2
					factor[a / f] ++
					factor[b / f] ++
					f4[i], f4[j] = 1, 1
					break
				}
			}
		}
	}
	var ans uint64 = 1
	for _, count := range factor {
		ans *= uint64(count + 1)
		ans %= 998244353
	}
	for i := 0;i < len(f4);i ++ {
		if f4[i] != 1 {
			ans *= 4
			ans %= 998244353
		}
	}
	fmt.Printf("%d", ans)
}

package main

import (
	"fmt"
)

func gcd(a, b uint64) uint64 {
	if a % b == 0 {
		return b
	} else {
		return gcd(b, a % b)
	}
}

func cubeRoot(a, left, right uint64) (uint64, bool) {
	if left > right {
		return 0, false
	}
	mid := (left + right) / 2
	ans := mid * mid * mid
	if ans == a {
		return mid, true
	} else if ans > a {
		return cubeRoot(a, left, mid - 1)
	} else {
		return cubeRoot(a, mid + 1, right)
	}
}

func root(a, left, right uint64) (uint64, bool) {
	if left > right {
		return 0, false
	}
	mid := (left + right) / 2
	ans := mid * mid
	if ans == a {
		return mid, true
	} else if ans > a {
		return root(a, left, mid - 1)
	} else {
		return root(a, mid + 1, right)
	}
}

var	factor map[uint64]int = map[uint64]int{}
func main() {
	var n int
	f4 := make([]uint64, 0, 500)
	fmt.Scanf("%d\n", &n)
	for i := 0;i < n;i ++ {
		var a uint64
		fmt.Scanf("%d\n", &a)
		if ro0, isSq0 := root(a, 1, 1500000000); isSq0 {
			if ro1, isSq1 := root(ro0, 1, 1500000000); isSq1 {
				factor[ro1] += 4
			} else {
				factor[ro0] += 2
			}
		} else if cr, isCr := cubeRoot(a, 1, 1400000); isCr {
			factor[cr] += 3
		} else {
			f4 = append(f4, a)
		}
	}
	for i := 0;i < len(f4);i ++ {
		a := f4[i]
		if a == 1 {
			continue
		}
		var flag bool
		for f, _ := range factor {
			if a % f == 0 {
				factor[f] ++
				factor[a / f] ++
				f4[i] = 1
				flag = true
				break
			}
		}
		if flag {
			continue
		} else {
			for j := i + 1;j < len(f4);j ++ {
				b := f4[j]
				if f := gcd(a, b); f != 1 {
					factor[f] += 2
					factor[a / f] ++
					factor[b / f] ++
					f4[i], f4[j] = 1, 1
					break
				}
			}
		}
	}
	var ans uint64 = 1
	for _, count := range factor {
		ans *= uint64(count + 1)
		ans %= 998244353
	}
	for i := 0;i < len(f4);i ++ {
		if f4[i] != 1 {
			ans *= 4
			ans %= 998244353
		}
	}
	fmt.Printf("%d", ans)
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"math"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func CF1033D(_r io.Reader, _w io.Writer) {
	const mod int64 = 998244353
	sqrt := func(a int64) int64 {
		r := int64(math.Round(math.Sqrt(float64(a))))
		if r*r == a {
			return r
		}
		return -1
	}
	cbrt := func(a int64) int64 {
		r := int64(math.Round(math.Cbrt(float64(a))))
		if r*r*r == a {
			return r
		}
		return -1
	}
	gcd := func(a, b int64) int64 {
		for a != 0 {
			a, b = b%a, a
		}
		return b
	}

	in := bufio.NewReader(_r)
	var n int
	Fscan(in, &n)
	cntv := map[int64]int{}
	cnte := map[int64]int{}
	vis := make([]bool, 0, n)
	a := make([]int64, 0, n)
	for ; n > 0; n-- {
		var v int64
		Fscan(in, &v)
		cntv[v]++
		if cntv[v] > 1 {
			continue
		}
		a = append(a, v)
		if r := cbrt(v); r != -1 {
			cnte[r] += 3
			vis = append(vis, true)
		} else if r := sqrt(v); r != -1 {
			if r4 := sqrt(r); r4 != -1 {
				cnte[r4] += 4
			} else {
				cnte[r] += 2
			}
			vis = append(vis, true)
		} else {
			vis = append(vis, false)
		}
	}

	ans := int64(1)
	for i, x := range a {
		if !vis[i] {
			for j, y := range a {
				if j == i {
					continue
				}
				if g := gcd(x, y); g > 1 {
					cnte[g] += cntv[x]
					cnte[x/g] += cntv[x]
					if !vis[j] {
						cnte[g] += cntv[y]
						cnte[y/g] += cntv[y]
						vis[j] = true
					}
					vis[i] = true
					break
				}
			}
		}
		if !vis[i] {
			c := cntv[x] + 1
			ans = ans * int64(c*c) % mod
		}
	}
	for _, c := range cnte {
		ans = ans * int64(c+1) % mod
	}
	Fprintln(_w, ans)
}

func main() { CF1033D(os.Stdin, os.Stdout) }

package main

import (
	"bufio"
	. "fmt"
	"io"
	"math"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func CF1033D(_r io.Reader, _w io.Writer) {
	const mod int64 = 998244353
	sqrt := func(a int64) int64 {
		r := int64(math.Round(math.Sqrt(float64(a))))
		if r*r == a {
			return r
		}
		return -1
	}
	cbrt := func(a int64) int64 {
		r := int64(math.Round(math.Cbrt(float64(a))))
		if r*r*r == a {
			return r
		}
		return -1
	}
	gcd := func(a, b int64) int64 {
		for a != 0 {
			a, b = b%a, a
		}
		return b
	}

	in := bufio.NewReader(_r)
	var n int
	Fscan(in, &n)
	cnts := map[int64]int{}
	vis := make([]bool, n)
	a := make([]int64, n)
	for i := range a {
		Fscan(in, &a[i])
		v := a[i]
		if r := cbrt(v); r != -1 {
			cnts[r] += 3
			vis[i] = true
		} else if r := sqrt(v); r != -1 {
			if r4 := sqrt(r); r4 != -1 {
				cnts[r4] += 4
			} else {
				cnts[r] += 2
			}
			vis[i] = true
		}
	}

	ans := int64(1)
	for i, x := range a {
		if !vis[i] {
			for j, y := range a {
				if j == i {
					continue
				}
				if g := gcd(x, y); g > 1 {
					cnts[g]++
					cnts[x/g]++
					if !vis[j] {
						cnts[g]++
						cnts[y/g]++
						vis[j] = true
					}
					vis[i] = true
					break
				}
			}
		}
		if !vis[i] {
			ans = ans * 4 % mod
		}
	}
	for _, c := range cnts {
		ans = ans * int64(c+1) % mod
	}
	Fprintln(_w, ans)
}

func main() { CF1033D(os.Stdin, os.Stdout) }

package main

import (
	"bufio"
	. "fmt"
	"io"
	"math"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func CF1033D(_r io.Reader, _w io.Writer) {
	const mod int64 = 998244353
	sqrt := func(a int64) int64 {
		r := int64(math.Round(math.Sqrt(float64(a))))
		if r*r == a {
			return r
		}
		return -1
	}
	cbrt := func(a int64) int64 {
		r := int64(math.Round(math.Cbrt(float64(a))))
		if r*r*r == a {
			return r
		}
		return -1
	}
	gcd := func(a, b int64) int64 {
		for a != 0 {
			a, b = b%a, a
		}
		return b
	}

	in := bufio.NewReader(_r)
	var n int
	Fscan(in, &n)
	cnts := map[int64]int{}
	vis := make([]bool, n)
	a := make([]int64, n)
	for i := range a {
		Fscan(in, &a[i])
		v := a[i]
		if r := cbrt(v); r != -1 {
			cnts[r] += 3
			vis[i] = true
		} else if r := sqrt(v); r != -1 {
			if r4 := sqrt(r); r4 != -1 {
				cnts[r4] += 4
			} else {
				cnts[r] += 2
			}
			vis[i] = true
		}
	}

	ans := int64(1)
	for i, x := range a {
		if !vis[i] {
			for j, y := range a {
				if j == i || y == x {
					continue
				}
				if g := gcd(x, y); g > 1 {
					cnts[g]++
					cnts[x/g]++
					if !vis[j] {
						cnts[g]++
						cnts[y/g]++
						vis[j] = true
					}
					vis[i] = true
					break
				}
			}
		}
		if !vis[i] {
			ans = ans * 4 % mod
		}
	}
	for _, c := range cnts {
		ans = ans * int64(c+1) % mod
	}
	Fprintln(_w, ans)
}

func main() { CF1033D(os.Stdin, os.Stdout) }


package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	n, _ := strconv.ParseInt(strings.Split(scanner.Text(), " ")[0], 10, 64)
	mid := (n*n + 1) / 2
	for scanner.Scan() {
		ws := strings.Split(scanner.Text(), " ")
		y, _ := strconv.ParseInt(ws[0], 10, 64)
		x, _ := strconv.ParseInt(ws[1], 10, 64)
		index := (int64(y)-1)*n + int64(x) - 1
		rank, extra := index/(2*n)*n, index%(2*n)
		if (x+y)%2 == 0 {
			if extra < n {
				rank += extra/2 + 1
			} else {
				rank += (extra%n+1)/2 + (n+1)/2
			}
			fmt.Println(rank)
		} else {
			if extra < n {
				rank += (extra + 1) / 2
			} else {
				rank += (extra%n+2)/2 + n/2
			}
			fmt.Println(mid + rank)
		}
	}
}

// 1027b
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func ReadInt32() int64 {
	scanner.Scan()
	ans, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	return ans
}
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)
	var n, q int64
	fmt.Scan(&n, &q)
	var h []string
	z := make([][2]int64, q)
	for i := 0; int64(i) < q; i++ {
		z[i][0], z[i][1] = ReadInt32(), ReadInt32()
	}
	for _, o := range z {
		var p int64
		xy := n*(o[0]-1) + o[1]
		if (o[0]+o[1])%2 == 0 {
			p = xy / 2
			if xy%2 > 0 {
				p++
			}
		} else {
			p = n*n/2 + xy/2
			if xy%2 > 0 {
				p++
			}
			if n%2 != 0 {
				p++
			}
		}
		h = append(h, strconv.FormatInt(p, 10))
	}
	fmt.Println(strings.Join(h, "\n"))
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main()  {

	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var n int64
	var q int
	fmt.Fscan(in, &n, &q)

	for t := 0; t < q; t++ {

		var a, b int64
		fmt.Fscan(in, &a, &b)

		var x int64
		if (a % 2 != 0 && b % 2 == 0) || (a % 2 == 0 && b % 2 != 0) {
			x += (n * n) / 2
			if n % 2 != 0 {
				x++
				//fmt.Fprintln(out, x)
				if a % 2 == 0 {
					x += (a - 2) / 2 * n
					x += n / 2
				} else {
					x += (a - 1) / 2 * n
				}
			} else {
				x += (a - 1) * n / 2
			}

		} else {

			if n % 2 != 0 {
				if a % 2 == 0 {
					x += (a - 2) / 2 * n
					x += n / 2 + 1
				} else {
					x += (a - 1) / 2 * n
				}
			} else {
				x += (a - 1) * n / 2
			}

		}

		x += (b + 1) / 2

		fmt.Fprintln(out, x)

	}

}
/*
4 12
1 1
1 2
1 3
1 4
2 1
2 2
2 3
2 4
3 1
3 2
3 3
3 4
*/

package main

import(
  "os"
  "bufio"
  "strconv"
  "fmt"
)

var scanner * bufio.Scanner

func next_int()(result int64){
  if !scanner.Scan() {
    panic("Unable to read next integer. Input has no data remain")
  }
  res, err := strconv.ParseInt(scanner.Text(), 10, 32)
  if err != nil {
    panic(err)
  }
  return res
}

func next_str()(result string){
  if !scanner.Scan() {
    panic("Unable to read next integer. Input has no data remain")
  }
  return scanner.Text()
}

func main() {

  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)

  n := next_int()
  q := int(next_int())

  for i := 1 ; i <= q; i++ {
    row := next_int()
    col := next_int()

    pattern := [] int64 {n / 2, n / 2}
    if (n & 1) > 0 {
      pattern[0]++
    }

    var offset int64 = 1
    if (row + col) & 1 > 0 {
      // position is odd, switch to the second half of values
      offset = (n * n + 1) / 2 + 1;
      // shift pattern
      sw := pattern[0];
      pattern[0] = pattern[1]
      pattern[1] = sw
    }

    plus := ((row - 1) / 2) * (pattern[0] + pattern[1])
    offset = offset + plus
    row = row - (((row - 1) / 2) * 2)
    if 2 == row {
      row -= 1
      offset += pattern[0]
    }
    offset += (col - 1) / 2;
    fmt.Println(offset)
  }
}

// 1027b
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func ReadInt32() int {
	scanner.Scan()
	ans, _ := strconv.Atoi(scanner.Text())
	return ans
}
func main() {

	var n, q int
	fmt.Scan(&n, &q)
	var h []string
	z := make([][2]int, q)
	for i := 0; i < q; i++ {
		z[i][0], z[i][1] = ReadInt32(), ReadInt32()
	}
	for _, o := range z {
		var p int
		xy := n*(o[0]-1) + o[1]
		if (o[0]+o[1])%2 == 0 {
			p = int(math.Ceil(float64(xy) / 2))
		} else {
			p = n*n/2 + int(math.Ceil(float64(xy)/2))
			if n%2 != 0 {
				p++
			}
		}
		h = append(h, strconv.Itoa(p))
	}
	fmt.Println(strings.Join(h, "\n"))
}

// 1027b
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func ReadInt32() int {
	scanner.Scan()
	ans, _ := strconv.Atoi(scanner.Text())
	return ans
}
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)
	var n, q int
	fmt.Scan(&n, &q)
	var h []string
	z := make([][2]int, q)
	for i := 0; i < q; i++ {
		z[i][0], z[i][1] = ReadInt32(), ReadInt32()
	}
	for _, o := range z {
		var p int
		xy := n*(o[0]-1) + o[1]
		if (o[0]+o[1])%2 == 0 {
			p = int(math.Ceil(float64(xy) / 2))
		} else {
			p = n*n/2 + int(math.Ceil(float64(xy)/2))
			if n%2 != 0 {
				p++
			}
		}
		h = append(h, strconv.Itoa(p))
	}
	fmt.Println(strings.Join(h, "\n"))
}

package main
import (
	 "fmt"
		"math"
		)
func main() {
	var n,q int
	fmt.Scan(&n,&q)
	var h []int
	for i:=0;i<q;i++{
		var x,y,p int
		fmt.Scan(&x,&y)
	  xy := n*(x-1)+y
			if (x+y)%2==0 {
					p = int(math.Ceil(float64(xy)/2))
				} else {
					p = n*n/2 + int(math.Ceil(float64(xy)/2))
				}
		h =append(h,p)
	}
	for _,s := range h {
	fmt.Println(s)
	}
}

package main
import "fmt"
func main() {
	var n,q int
	fmt.Scan(&n,&q)
	var h []int
	for i:=0;i<q;i++{
		var x,y,p int
		fmt.Scan(&x,&y)
	  xy := n*(x-1)+y
		if n%2!=0 {
			if (x+y)%2==0 {
					p = xy/2 + 1
				} else {
					p = n*n/2 + xy/2 +1
				}
		}else{
			if (x+y)%2==0 {
				p =xy/2 + 1
			}else{
				p =xy/2+1+n*n/2
				}
		}
		h =append(h,p)
	}
	for _,s := range h {
	fmt.Println(s)
	}
}

// 1027b
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func ReadInt32() int64 {
	scanner.Scan()
	ans, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	return ans
}
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)
	var n, q int64
	fmt.Scan(&n, &q)
	var h []string
	z := make([][2]int64, q)
	for i := 0; int64(i) < q; i++ {
		z[i][0], z[i][1] = ReadInt32(), ReadInt32()
	}
	for _, o := range z {
		var p int64
		xy := n*(o[0]-1) + o[1]
		if (o[0]+o[1])%2 == 0 {
			p = int64(math.Ceil(float64(xy) / 2))
		} else {
			p = n*n/2 + int64(math.Ceil(float64(xy)/2))
			if n%2 != 0 {
				p++
			}
		}
		h = append(h, strconv.FormatInt(p, 10))
	}
	fmt.Println(strings.Join(h, "\n"))
}

// 1027b
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func ReadInt32() int64 {
	scanner.Scan()
	ans, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	return ans
}
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)
	var n, q int
	fmt.Scan(&n, &q)
	var h []string
	z := make([][2]int64, q)
	for i := 0; i < q; i++ {
		z[i][0], z[i][1] = ReadInt32(), ReadInt32()
	}
	for _, o := range z {
		var p int
		xy := int64(n)*(o[0]-1) + o[1]
		if (o[0]+o[1])%2 == 0 {
			p = int(math.Ceil(float64(xy) / 2))
		} else {
			p = n*n/2 + int(math.Ceil(float64(xy)/2))
			if n%2 != 0 {
				p++
			}
		}
		h = append(h, strconv.Itoa(p))
	}
	fmt.Println(strings.Join(h, "\n"))
}

package main
import (
	 "fmt"
		"math"
		)
func main() {
	var n,q int
	fmt.Scan(&n,&q)
	var h []int
	for i:=0;i<q;i++{
		var x,y,p int
		fmt.Scan(&x,&y)
	  xy := n*(x-1)+y
			if (x+y)%2==0 {
					p = int(math.Ceil(float64(xy)/2))
				} else {
					p = n*n/2 + int(math.Ceil(float64(xy)/2))+1
				}
		h =append(h,p)
	}
	for _,s := range h {
	fmt.Println(s)
	}
}


// Author: sighduck
// URL: https://codeforces.com/problemset/problem/1153/C

package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func isValidSequence(n int, s []string) bool {
	left := 0
	right := 0
	for i := 0; i < n; i++ {
		if s[i] == "(" {
			left += 1
		} else if s[i] == ")" {
			right += 1
		}
		if right > left {
			return false
		}
		if 0 < i && i < n-1 && left == right {
			return false
		}
	}
	return left == right
}

func Solve(n int, s string) string {
	if n%2 == 1 {
		return ":("
	}
	leftRemaining := n / 2
	rightRemaining := n / 2
	for i := 0; i < n; i++ {
		if string(s[i]) == "(" {
			leftRemaining -= 1
		} else if string(s[i]) == ")" {
			rightRemaining -= 1
		}
	}
	answer := make([]string, n)
	for i := 0; i < n; i++ {
		if string(s[i]) != "?" {
			answer[i] = string(s[i])
		} else if string(s[i]) == "?" && leftRemaining > 0 {
			answer[i] = "("
			leftRemaining -= 1
		} else if string(s[i]) == "?" && rightRemaining > 0 {
			answer[i] = ")"
			rightRemaining -= 1
		}
	}
	if isValidSequence(n, answer) {
		return strings.Join(answer, "")
	}
	return ":("
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n int
	var s string
	fmt.Fscanf(reader, "%d\n%s\n", &n, &s)
	fmt.Fprintf(writer, "%s\n", Solve(n, s))
}

package main

import (
    "bufio"
    "os"
    "fmt"
    "strconv"
)

func main() {
    input := bufio.NewScanner(os.Stdin)
    inputbuf := make([]byte, 0, 64 * 1024)  // 64 KB of input buffer
    input.Buffer(inputbuf, 1024 * 1024)     // 1 MB of maximum token size
    input.Split(bufio.ScanWords)

    input.Scan()
    n, _ := strconv.Atoi(input.Text())

    if n <= 1 {
        fmt.Println(":(")
        return
    }

    input.Scan()
    s := input.Text()

    if s[0] == ')' || s[n - 1] == '(' {
        fmt.Println(":(")
        return
    }

    cr := make([]int, n, n)
    cl := make([]int, n, n)
    for i := n - 2; i >= 1; i-- {
        cr[i] = cr[i + 1]
        if s[i] != '(' {
            cr[i]++
        }
    }
    for i := n - 2; i >= 1; i-- {
        cl[i] = cl[i + 1]
        if s[i] == '(' {
            cl[i]++
        }
    }

    result := make([]byte, 0, n)
    result = append(result, '(')

    lp := 0
    for i := 1; i < n - 1; i++ {
        switch s[i] {
        case '(':
            lp++
            result = append(result, '(')

        case ')':
            lp--
            result = append(result, ')')

        case '?':
            if lp + 1 + cl[i + 1] <= cr[i + 1] {
                lp++
                result = append(result, '(')
            } else {
                lp--
                result = append(result, ')')
            }
        }

        if lp < 0 {
            fmt.Println(":(")
            return
        }
    }

    if lp != 0 {
        fmt.Println(":(")
        return
    }

    result = append(result, ')')

    fmt.Println(string(result))
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)

	var n int
	fmt.Fscanln(in, &n)

	s := make([]rune, n)
	for i := range s {
		s[i], _, _ = in.ReadRune()
	}

	if n % 2 != 0 {
		fmt.Println(":(")
		return
	}

	if n == 0 {
		fmt.Println()
		return
	}

	if s[0] != '(' && s[0] != '?' {
		fmt.Println(":(")
		return
	}
	s[0] = '('

	if s[n-1] != ')' && s[n-1] != '?' {
		fmt.Println(":(")
		return
	}
	s[n-1] = ')'

	lefts := n / 2 - 1
	for i := 1; i < n - 1; i++ {
		if s[i] == '(' {
			lefts--
		}
	}

	if lefts < 0 {
		fmt.Println(":(")
		return
	}

	opened := 0
	for i := 1; i < n - 1; i++ {
		if s[i] == '?' {
			if lefts > 0 {
				s[i] = '('
				lefts--
			} else {
				s[i] = ')'
			}
		}
		if s[i] == ')' {
			if opened == 0 {
				fmt.Println(":(")
				return
			}
			opened--
		} else {
			opened++
		}
	}

	fmt.Println(string(s))
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	buf := bufio.NewReader(os.Stdin)

	var n int
	fmt.Fscanf(buf, "%d\n", &n)

	mat := make([]byte, n)
	fmt.Fscanf(buf, "%s\n", &mat)
	if 1 == (n%2) || mat[0] == ')' || mat[n-1] == '(' {
		fmt.Printf(":(\n")
		return
	}
	mat[0] = '('
	mat[n-1] = ')'
	cnt := 0
	for i := 0; i < n; i++ {
		if mat[i] == '(' {
			cnt++
		}
	}
	if cnt > n/2 {
		fmt.Printf(":(\n")
		return
	}
	cnt = n/2 - cnt
	for i := 1; i < n-1; i++ {
		if mat[i] == '?' {
			if cnt > 0 {
				mat[i] = '('
				cnt--
			} else {
				mat[i] = ')'
			}
		}
	}
	if cnt > 0 {
		fmt.Printf(":(\n")
		return
	}
	cnt = 0
	for i := 0; i < n-1; i++ {
		if mat[i] == '(' {
			cnt++
		} else {
			cnt--
		}
		if cnt == 0 {
			fmt.Printf(":(\n")
			return
		}
	}
	fmt.Printf("%s\n", mat)
}

/**
4
()?)
 */

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	buf := bufio.NewReader(os.Stdin)

	var n int
	fmt.Fscanf(buf, "%d\n", &n)

	mat := make([]byte, n)
	fmt.Fscanf(buf, "%s\n", &mat)
	if 1==(n%1) || (mat[0]!='('&&mat[0]!='?')||(mat[n-1]!=')'&&mat[n-1]!='?'){
		fmt.Printf(":(\n")
		return
	}
	mat[0] = '('
	mat[n-1] =')'
	cnt := 0
	for i:=0;i < n;i++{
		if mat[i] == '('{
			cnt++
		}
	}
	if cnt > n/2{
		fmt.Printf(":(\n")
		return
	}
	cnt = n/2-cnt
	for i:=1;i < n-1;i++{
		if mat[i] == '?'{
			if cnt > 0{
				mat[i]='('
				cnt--
			}else{
				mat[i] = ')'
			}
		}
	}
	if cnt > 0{
		fmt.Printf(":(\n")
		return
	}
	cnt = 0
	for i:=0;i < n-1;i++{
		if mat[i]=='('{
			cnt++
		}else{
			cnt--
		}
		if cnt==0{
			fmt.Printf(":(\n")
			return
		}
	}
	fmt.Printf("%s\n",mat)
}

package main

import (
    "bufio"
    "os"
    "fmt"
)

func main() {
    input := bufio.NewScanner(os.Stdin)
    input.Split(bufio.ScanWords)

    input.Scan()
    // Ignore n

    input.Scan()
    s := input.Text()

    result := make([]byte, 0, len(s))

    if s[0] == ')' || s[len(s) - 1] == '(' {
        fmt.Println(":(")
        return
    }
    if s[0] == '?' {
        result[0] = '('
    }

    lp := 0
    for i := 0; i < len(s) - 1; i++ {
        switch s[i] {
        case '(':
            result = append(result, '(')
            lp++

        case ')':
            result = append(result, ')')
            lp--

        case '?':
            if lp == 1 {
                result = append(result, '(')
                lp++
            } else {
                result = append(result, ')')
                lp--
            }
        }
    }
    result = append(result, ')')
    lp--

    if lp != 0 {
        fmt.Println(":(")
        return
    }

    fmt.Println(string(result))
}

package main

import (
    "bufio"
    "os"
    "fmt"
    "strconv"
)

func main() {
    input := bufio.NewScanner(os.Stdin)
    inputbuf := make([]byte, 0, 64 * 1024)  // 64 KB of input buffer
    input.Buffer(inputbuf, 1024 * 1024)     // 1 MB of maximum token size
    input.Split(bufio.ScanWords)

    input.Scan()
    n, _ := strconv.Atoi(input.Text())

    input.Scan()
    s := input.Text()

    if s[0] == ')' || s[n - 1] == '(' {
        fmt.Println(":(")
        return
    }

    cr := make([]int, n, n)
    cl := make([]int, n, n)
    for i := n - 2; i >= 1; i-- {
        cr[i] = cr[i + 1]
        if s[i] != '(' {
            cr[i]++
        }
    }
    for i := n - 2; i >= 1; i-- {
        cl[i] = cl[i + 1]
        if s[i] == '(' {
            cl[i]++
        }
    }

    result := make([]byte, 0, n)
    result = append(result, '(')

    lp := 0
    for i := 1; i < n - 1; i++ {
        switch s[i] {
        case '(':
            lp++
            result = append(result, '(')

        case ')':
            lp--
            result = append(result, ')')

        case '?':
            if lp + 1 + cl[i + 1] <= cr[i + 1] {
                lp++
                result = append(result, '(')
            } else {
                lp--
                result = append(result, ')')
            }
        }

        if lp < 0 {
            fmt.Println(":(")
            return
        }
    }

    if lp != 0 {
        fmt.Println(":(")
        return
    }

    result = append(result, ')')

    fmt.Println(string(result))
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)

	var n int
	fmt.Fscanln(in, &n)

	s := make([]rune, n)
	for i := range s {
		s[i], _, _ = in.ReadRune()
	}

	if n % 2 != 0 {
		fmt.Println(":(")
		return
	}

	if s[0] != '(' && s[0] != '?' {
		fmt.Println(":(")
		return
	}
	s[0] = '('

	if s[n-1] != ')' && s[n-1] != '?' {
		fmt.Println(":(")
		return
	}
	s[n-1] = ')'

	lefts := n / 2 - 1
	rights := n / 2 - 1
	for i := 1; i < n - 1; i++ {
		if s[i] == '(' {
			lefts--
		} else if s[i] == ')' {
			rights--
		}
	}

	opened := 0
	for i := 1; i < n - 1; i++ {
		if s[i] == ')' && opened == 0 {
			fmt.Println(":(")
			return
		}
		if s[i] == '?' {
			if lefts > 0 {
				s[i] = '('
				lefts--
				opened++
			} else {
				s[i] = ')'
				opened--
				if opened < 0 {
					fmt.Println(":(")
					return
				}
			}
		}
	}

	fmt.Println(string(s))
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)

	var n int
	fmt.Fscanln(in, &n)

	s := make([]rune, n)
	for i := range s {
		s[i], _, _ = in.ReadRune()
	}

	if n % 2 != 0 {
		fmt.Println(":(")
		return
	}

	if n == 0 {
		fmt.Println()
		return
	}

	if s[0] != '(' && s[0] != '?' {
		fmt.Println(":(")
		return
	}
	s[0] = '('

	if s[n-1] != ')' && s[n-1] != '?' {
		fmt.Println(":(")
		return
	}
	s[n-1] = ')'

	lefts := n / 2 - 1
	for i := 1; i < n - 1; i++ {
		if s[i] == '(' {
			lefts--
		}
	}

	opened := 0
	for i := 1; i < n - 1; i++ {
		if s[i] == '?' {
			if lefts > 0 {
				s[i] = '('
				lefts--
			} else {
				s[i] = ')'
			}
		}
		if s[i] == ')' {
			if opened == 0 {
				fmt.Println(":(")
				return
			}
			opened--
		} else {
			opened++
		}
	}

	fmt.Println(string(s))
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)

	var n int
	fmt.Fscanln(in, &n)

	s := make([]rune, n)
	for i := range s {
		s[i], _, _ = in.ReadRune()
	}

	if n % 2 != 0 {
		fmt.Println(":(")
		return
	}

	if s[0] != '(' && s[0] != '?' {
		fmt.Println(":(")
		return
	}
	s[0] = '('

	if s[n-1] != ')' && s[n-1] != '?' {
		fmt.Println(":(")
		return
	}
	s[n-1] = ')'

	lefts := n / 2 - 1
	for i := 1; i < n - 1; i++ {
		if s[i] == '(' {
			lefts--
		}
	}

	opened := 0
	for i := 1; i < n - 1; i++ {
		if s[i] == ')' {
			if opened == 0 {
				fmt.Println(":(")
				return
			}
			opened--
		} else if s[i] == '?' {
			if lefts > 0 {
				s[i] = '('
				lefts--
				opened++
			} else {
				if opened == 0 {
					fmt.Println(":(")
					return
				}
				s[i] = ')'
				opened--
			}
		} else {
			opened++
		}
	}

	fmt.Println(string(s))
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)

	var n int
	fmt.Fscanln(in, &n)

	s := make([]rune, n)
	for i := range s {
		s[i], _, _ = in.ReadRune()
	}

	if n % 2 != 0 {
		fmt.Println(":(")
		return
	}

	if s[0] != '(' && s[0] != '?' {
		fmt.Println(":(")
		return
	}
	s[0] = '('

	if s[n-1] != ')' && s[n-1] != '?' {
		fmt.Println(":(")
		return
	}
	s[n-1] = ')'

	lefts := n / 2 - 1
	for i := 1; i < n - 1; i++ {
		if s[i] == '(' {
			lefts--
		}
	}

	opened := 0
	for i := 1; i < n - 1; i++ {
		if s[i] == '?' {
			if lefts > 0 {
				s[i] = '('
				lefts--
			} else {
				s[i] = ')'
			}
		}
		if s[i] == ')' {
			if opened == 0 {
				fmt.Println(":(")
				return
			}
			opened--
		} else {
			opened++
		}
	}

	fmt.Println(string(s))
}

// Author: sighduck
// URL: https://codeforces.com/problemset/problem/1153/C

package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func isValidSequence(n int, s []string) bool {
	left := 0
	right := 0
	for i := 0; i < n; i++ {
		if s[i] == "(" {
			left += 1
		} else if s[i] == ")" {
			right += 1
		}
		if right > left {
			return false
		}
		if 0 < i && i < n-1 && left == right {
			return false
		}
	}
	return left == right
}

func Solve(n int, s string) string {
	leftRemaining := n / 2
	rightRemaining := n / 2
	for i := 0; i < n; i++ {
		if string(s[i]) == "(" {
			leftRemaining -= 1
		} else if string(s[i]) == ")" {
			rightRemaining -= 1
		}
	}
	answer := make([]string, n)
	for i := 0; i < n; i++ {
		if string(s[i]) != "?" {
			answer[i] = string(s[i])
		} else if string(s[i]) == "?" && leftRemaining > 0 {
			answer[i] = "("
			leftRemaining -= 1
		} else if string(s[i]) == "?" && rightRemaining > 0 {
			answer[i] = ")"
			rightRemaining -= 1
		}
	}
	if isValidSequence(n, answer) {
		return strings.Join(answer, "")
	}
	return ":("
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n int
	var s string
	fmt.Fscanf(reader, "%d\n%s\n", &n, &s)
	fmt.Fprintf(writer, "%s\n", Solve(n, s))
}


package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
	"sort"
)

type pair struct {
	l int
	r int
}

type line struct {
	l int
	r int
	cst int
}

// Credits - github.com/EndlessCheng/codeforces-go
func solve(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	T:= 0
	for Fscan(in, &T); T > 0; T-- {
		var n int
		Fscan(in, &n)
		a:=make([]pair,n+1)
		for i:=0;i<n;i++{
			Fscan(in,&a[i].l,&a[i].r)
		}

		a[n].l=-100000000
		a[n].r=100000000
		n++

		sort.SliceStable(a, func(i, j int) bool {
			if a[i].r-a[i].l==a[j].r-a[j].l{
				return a[i].l<a[j].l
			}
			return a[i].r-a[i].l<a[j].r-a[j].l
		})

		dp:=make([]int,n)

		bs:=func(a []pair,s,r int) int {
			l:=0
            r++
			for r-l>1{
				m:=(l+r)/2
				if a[m].l<s{
					l=m
				} else{
					r=m
				}
			}
			return a[l].r
		}

		solve:=func(l,r int) int{
			aa:=make([]line,0)
			for i,v:=range(a){
				if l<=v.l&&v.r<=r{
					aa=append(aa,line{v.l,v.r,dp[i]})
				}
			}

			sort.SliceStable(aa, func(i, j int) bool {
				if aa[i].r==aa[j].r{
					return aa[i].l<aa[j].l
				}
				return aa[i].r<aa[j].r
			})

			n:=len(aa)

			que:=make([]pair,n+1)
			top:=0
			que[top].l=-200000000

			for _,v:=range(aa){
				cur:=bs(que,v.l,top)
				// for k,vv:=range(aa){
				// 	if vv.r<v.l && cur<dp2[k]{
				// 		cur=dp2[k]
				// 	}
				// }

				cur+=v.cst
				if cur>=que[top].r {
					top++
					que[top]=pair{v.r,cur}
				}
			}
			return que[top].r
		}

		// Fprintln(out,a)
		for i,v:=range(a){
			dp[i]=1+solve(v.l,v.r)
		}
		Fprintln(out,dp[n-1]-1)
	}
}

func main() { solve(os.Stdin, os.Stdout) }

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"sort"
)

func main() {
	io := NewFastIO(os.Stdin, os.Stdout)
	defer io.Flush()

	for t := io.NextInt(); t > 0; t-- {
		n := io.NextInt()
		a := make([][]int, n)
		var v []int
		for i := range a {
			a[i] = io.NextInts(2)
			v = append(v, a[i]...)
		}

		sort.Ints(v)
		idx := func(i int) int {
			return sort.Search(len(v), func(j int) bool { return i <= v[j] })
		}
		m := 2 * n
		at := make([][]int, m)
		for _, p := range a {
			l, r := idx(p[0]), idx(p[1])
			at[l] = append(at[l], r)
		}

		dp := make([][]int, m)
		for i := range dp {
			dp[i] = make([]int, m)
			for j := range dp[i] {
				dp[i][j] = -1
			}
		}
		var f func(int, int) int
		f = func(i, j int) int {
			if i > j {
				return 0
			}
			if dp[i][j] == -1 {
				dp[i][j] = f(i+1, j)
				exact := 0
				for _, r := range at[i] {
					if r == j {
						exact++
					} else if r < j {
						dp[i][j] = max(dp[i][j], f(i, r)+f(r+1, j))
					}
				}
				dp[i][j] += exact
			}
			return dp[i][j]
		}

		ans := f(0, m-1)
		io.Println(ans)
	}
}

func max(i, j int) int {
	if i > j {
		return i
	}
	return j
}

type FastIO struct {
	*bufio.Reader
	*bufio.Writer
	c [1]byte
}

func NewFastIO(r io.Reader, w io.Writer) *FastIO {
	return &FastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

func (f *FastIO) readC() byte {
	f.Read(f.c[:])
	return f.c[0]
}

func (f *FastIO) NextInt() int {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := 0
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}

func (f *FastIO) NextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt()
	}
	return a
}

func (f *FastIO) Println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"os"
	"sort"
)

func main() {
	reader := bufio.NewReader(os.Stdin)

	tc := readNum(reader)
	var buf bytes.Buffer
	for tc > 0 {
		tc--
		n := readNum(reader)
		L := make([][]int, n)
		for i := 0; i < n; i++ {
			L[i] = readNNums(reader, 2)
		}
		res := solve(n, L)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}
	fmt.Print(buf.String())
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

const MAX_X = 200010

func solve(n int, segs [][]int) int {
	lines := make([]Line, n, n+1)
	for i := 0; i < n; i++ {
		lines[i] = Line{segs[i][0], segs[i][1]}
	}
	lines = append(lines, Line{0, MAX_X})
	sort.Sort(Lines(lines))
	n++

	G := make([][]int, n)

	for i := 0; i < n; i++ {
		G[i] = make([]int, 0, 10)
	}

	check := func(i, j int) bool {
		a, b := lines[i], lines[j]
		return a.l <= b.l && b.r <= a.r
	}

	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			if check(i, j) {
				G[i] = append(G[i], j)
			}
		}
	}

	dp := make([]int, n)
	var dfs func(u int) int

	dfs = func(u int) int {
		if dp[u] != 0 {
			return dp[u]
		}
		if len(G[u]) == 0 {
			dp[u] = 1
			return 1
		}
		var root *Node
		var best int
		for _, v := range G[u] {
			tmp := dfs(v)
			cur := lines[v]
			x := root.FindMaxBefore(cur.l - 1)
			if x+tmp > best {
				best = x + tmp
			}
			root = root.Insert(cur.r, x+tmp, 0, MAX_X)
		}

		best++

		dp[u] = best

		return best
	}
	res := dfs(0)

	return res - 1
}

type Node struct {
	left, right *Node
	start, end  int
	maxValue    int
}

func NewNode(start, end, val int) *Node {
	node := new(Node)
	node.start = start
	node.end = end
	node.maxValue = val
	return node
}

func (node *Node) Insert(p, v int, start, end int) *Node {
	if node == nil {
		node = NewNode(start, end, v)
	}
	if node.start == node.end {
		node.maxValue = max(node.maxValue, v)
		return node
	}
	mid := (node.start + node.end) / 2
	if p <= mid {
		node.left = node.left.Insert(p, v, start, mid)
	} else {
		node.right = node.right.Insert(p, v, mid+1, end)
	}
	if node.left == nil {
		node.maxValue = node.right.maxValue
	} else if node.right == nil {
		node.maxValue = node.left.maxValue
	} else {
		node.maxValue = max(node.left.maxValue, node.right.maxValue)
	}

	return node
}

func (node *Node) FindMaxBefore(p int) int {
	if node == nil {
		return 0
	}
	if node.start == node.end {
		return node.maxValue
	}
	mid := (node.start + node.end) / 2
	if p <= mid {
		return node.left.FindMaxBefore(p)
	}
	res := node.right.FindMaxBefore(p)
	if node.left != nil {
		return max(node.left.maxValue, res)
	}
	return res
}

func max(a, b int) int {
	if a >= b {
		return a
	}
	return b
}

type Line struct {
	l, r int
}

type Lines []Line

func (lines Lines) Len() int {
	return len(lines)
}

func (lines Lines) Less(i, j int) bool {
	return lines[i].l < lines[j].l || lines[i].l == lines[j].l && lines[i].r > lines[j].r
}

func (lines Lines) Swap(i, j int) {
	lines[i], lines[j] = lines[j], lines[i]
}

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"os"
	"sort"
)

func main() {
	reader := bufio.NewReader(os.Stdin)

	tc := readNum(reader)
	var buf bytes.Buffer
	for tc > 0 {
		tc--
		n := readNum(reader)
		L := make([][]int, n)
		for i := 0; i < n; i++ {
			L[i] = readNNums(reader, 2)
		}
		res := solve(n, L)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}
	fmt.Print(buf.String())
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

const MAX_X = 200010

func solve(n int, segs [][]int) int {
	ps := make([]int, 0, 2*n)
	for i := 0; i < n; i++ {
		seg := segs[i]
		u, v := seg[0], seg[1]
		ps = append(ps, u)
		ps = append(ps, v)
	}
	sort.Ints(ps)
	ii := make(map[int]int)
	var m int
	for i := 1; i <= len(ps); i++ {
		if i == len(ps) || ps[i] > ps[i-1] {
			ii[ps[i-1]] = m
			m++
		}
	}

	rg := make([][]int, m)

	for i := 0; i < m; i++ {
		rg[i] = make([]int, 0, 10)
	}

	for i := 0; i < n; i++ {
		cur := segs[i]
		u, v := cur[0], cur[1]
		j, k := ii[u], ii[v]
		rg[j] = append(rg[j], k)
	}

	dp := make([][]int, m)
	for i := 0; i < m; i++ {
		dp[i] = make([]int, m)
		for j := 0; j < m; j++ {
			dp[i][j] = -1
		}
		sort.Ints(rg[i])
	}

	var count func(l, r int) int

	count = func(l, r int) int {
		if l > r {
			return 0
		}
		if dp[l][r] >= 0 {
			return dp[l][r]
		}
		v := rg[l]
		j := sort.SearchInts(v, r)
		var add int
		if j < len(v) && v[j] == r {
			add++
		}
		dp[l][r] = count(l+1, r)
		for i := 0; i < len(v); i++ {
			if v[i] >= r {
				break
			}
			dp[l][r] = max(dp[l][r], count(l, v[i])+count(v[i]+1, r))
		}
		dp[l][r] += add

		return dp[l][r]
	}

	return count(0, m-1)
}

func solve1(n int, segs [][]int) int {
	lines := make([]Line, n, n+1)
	for i := 0; i < n; i++ {
		lines[i] = Line{segs[i][0], segs[i][1]}
	}
	lines = append(lines, Line{0, MAX_X})
	sort.Sort(Lines(lines))
	n++

	G := make([][]int, n)

	for i := 0; i < n; i++ {
		G[i] = make([]int, 0, 10)
	}

	check := func(i, j int) bool {
		a, b := lines[i], lines[j]
		return a.l <= b.l && b.r <= a.r
	}

	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			if check(i, j) {
				G[i] = append(G[i], j)
			}
		}
	}

	dp := make([]int, n)
	var dfs func(u int) int

	dfs = func(u int) int {
		if dp[u] != 0 {
			return dp[u]
		}
		if len(G[u]) == 0 {
			dp[u] = 1
			return 1
		}
		var root *Node
		var best int
		for _, v := range G[u] {
			tmp := dfs(v)
			cur := lines[v]
			x := root.FindMaxBefore(cur.l - 1)
			if x+tmp > best {
				best = x + tmp
			}
			root = root.Insert(cur.r, x+tmp, 0, MAX_X)
		}

		best++

		dp[u] = best

		return best
	}
	res := dfs(0)

	return res - 1
}

type Node struct {
	left, right *Node
	start, end  int
	maxValue    int
}

func NewNode(start, end, val int) *Node {
	node := new(Node)
	node.start = start
	node.end = end
	node.maxValue = val
	return node
}

func (node *Node) Insert(p, v int, start, end int) *Node {
	if node == nil {
		node = NewNode(start, end, v)
	}
	if node.start == node.end {
		node.maxValue = max(node.maxValue, v)
		return node
	}
	mid := (node.start + node.end) / 2
	if p <= mid {
		node.left = node.left.Insert(p, v, start, mid)
	} else {
		node.right = node.right.Insert(p, v, mid+1, end)
	}
	if node.left == nil {
		node.maxValue = node.right.maxValue
	} else if node.right == nil {
		node.maxValue = node.left.maxValue
	} else {
		node.maxValue = max(node.left.maxValue, node.right.maxValue)
	}

	return node
}

func (node *Node) FindMaxBefore(p int) int {
	if node == nil {
		return 0
	}
	if node.start == node.end {
		return node.maxValue
	}
	mid := (node.start + node.end) / 2
	if p <= mid {
		return node.left.FindMaxBefore(p)
	}
	res := node.right.FindMaxBefore(p)
	if node.left != nil {
		return max(node.left.maxValue, res)
	}
	return res
}

func max(a, b int) int {
	if a >= b {
		return a
	}
	return b
}

type Line struct {
	l, r int
}

type Lines []Line

func (lines Lines) Len() int {
	return len(lines)
}

func (lines Lines) Less(i, j int) bool {
	return lines[i].l < lines[j].l || lines[i].l == lines[j].l && lines[i].r > lines[j].r
}

func (lines Lines) Swap(i, j int) {
	lines[i], lines[j] = lines[j], lines[i]
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
	"sort"
)

type pair struct {
	l int
	r int
}

type line struct {
	l int
	r int
	cst int
}

// Credits - github.com/EndlessCheng/codeforces-go
func solve(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	T:= 0
	for Fscan(in, &T); T > 0; T-- {
		var n int
		Fscan(in, &n)
		a:=make([]pair,n+1)
		for i:=0;i<n;i++{
			Fscan(in,&a[i].l,&a[i].r)
		}

		a[n].l=-100000000
		a[n].r=100000000
		n++

		sort.SliceStable(a, func(i, j int) bool {
			if a[i].r-a[i].l==a[j].r-a[j].l{
				return a[i].l<a[j].l
			}
			return a[i].r-a[i].l<a[j].r-a[j].l
		})

		dp:=make([]int,n)

		bs:=func(a []pair,s,r int) int {
			l:=0

			for r-l>1{
				m:=(l+r)/2
				if a[m].l<s{
					l=m
				} else{
					r=m
				}
			}
			return a[l].r
		}

		solve:=func(l,r int) int{
			aa:=make([]line,0)
			for i,v:=range(a){
				if l<=v.l&&v.r<=r{
					aa=append(aa,line{v.l,v.r,dp[i]})
				}
			}

			sort.SliceStable(aa, func(i, j int) bool {
				if aa[i].r==aa[j].r{
					return aa[i].l<aa[j].l
				}
				return aa[i].r<aa[j].r
			})

			n:=len(aa)

			que:=make([]pair,n+1)
			top:=0
			que[top].l=-200000000

			for _,v:=range(aa){
				cur:=bs(que,v.l,top)
				// for k,vv:=range(aa){
				// 	if vv.r<v.l && cur<dp2[k]{
				// 		cur=dp2[k]
				// 	}
				// }

				cur+=v.cst
				if cur>=que[top].r {
					top++
					que[top]=pair{v.r,cur}
				}
			}
			return que[top].r
		}

		// Fprintln(out,a)
		for i,v:=range(a){
			dp[i]=1+solve(v.l,v.r)
		}
		Fprintln(out,dp[n-1]-1)
	}
}

func main() { solve(os.Stdin, os.Stdout) }

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"os"
	"sort"
)

func main() {
	reader := bufio.NewReader(os.Stdin)

	tc := readNum(reader)
	var buf bytes.Buffer
	for tc > 0 {
		tc--
		n := readNum(reader)
		L := make([][]int, n)
		for i := 0; i < n; i++ {
			L[i] = readNNums(reader, 2)
		}
		res := solve(n, L)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}
	fmt.Print(buf.String())
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

const MAX_X = 200010

func solve(n int, segs [][]int) int {
	lines := make([]Line, n, n+1)
	for i := 0; i < n; i++ {
		lines[i] = Line{segs[i][0], segs[i][1]}
	}
	lines = append(lines, Line{1, MAX_X})
	sort.Sort(Lines(lines))
	n++

	G := make([][]int, n)

	for i := 0; i < n; i++ {
		G[i] = make([]int, 0, 10)
	}

	check := func(i, j int) bool {
		a, b := lines[i], lines[j]
		return a.l <= b.l && b.r <= a.r
	}

	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			if check(i, j) {
				G[i] = append(G[i], j)
			}
		}
	}

	dp := make([]int, n)
	var dfs func(u int) int

	dfs = func(u int) int {
		if dp[u] != 0 {
			return dp[u]
		}
		if len(G[u]) == 0 {
			dp[u] = 1
			return 1
		}
		root := NewNode(lines[u].l, lines[u].r, 0)
		var best int
		for _, v := range G[u] {
			tmp := dfs(v)
			cur := lines[v]
			x := root.FindMaxBefore(cur.l-1, 0, lines[u].r)
			if x+tmp > best {
				best = x + tmp
			}
			root = root.Insert(cur.r, x+tmp, 0, lines[u].r)
		}

		best++

		dp[u] = best

		return best
	}
	res := dfs(0)

	return res - 1
}

type Node struct {
	left, right *Node
	start, end  int
	maxValue    int
}

func NewNode(start, end, val int) *Node {
	node := new(Node)
	node.start = start
	node.end = end
	node.maxValue = val
	return node
}

func (node *Node) Insert(p, v int, start, end int) *Node {
	if node == nil {
		node = NewNode(start, end, v)
	}
	if node.start == node.end {
		return node
	}
	mid := (node.start + node.end) / 2
	if p <= mid {
		node.left = node.left.Insert(p, v, start, mid)
	} else {
		node.right = node.right.Insert(p, v, mid+1, end)
	}
	if node.left == nil {
		node.maxValue = node.right.maxValue
	} else if node.right == nil {
		node.maxValue = node.left.maxValue
	} else {
		node.maxValue = max(node.left.maxValue, node.right.maxValue)
	}

	return node
}

func (node *Node) FindMaxBefore(p int, start, end int) int {
	if node == nil {
		return 0
	}
	if node.start == node.end {
		return node.maxValue
	}
	mid := (node.start + node.end) / 2
	if p <= mid {
		return node.left.FindMaxBefore(p, start, mid)
	}
	res := node.right.FindMaxBefore(p, mid+1, end)
	if node.left != nil {
		return max(node.left.maxValue, res)
	}
	return res
}

func max(a, b int) int {
	if a >= b {
		return a
	}
	return b
}

type Line struct {
	l, r int
}

type Lines []Line

func (lines Lines) Len() int {
	return len(lines)
}

func (lines Lines) Less(i, j int) bool {
	return lines[i].l < lines[j].l || lines[i].l == lines[j].l && lines[i].r > lines[j].r
}

func (lines Lines) Swap(i, j int) {
	lines[i], lines[j] = lines[j], lines[i]
}

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"os"
	"sort"
)

func main() {
	reader := bufio.NewReader(os.Stdin)

	tc := readNum(reader)
	var buf bytes.Buffer
	for tc > 0 {
		tc--
		n := readNum(reader)
		L := make([][]int, n)
		for i := 0; i < n; i++ {
			L[i] = readNNums(reader, 2)
		}
		res := solve(n, L)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}
	fmt.Print(buf.String())
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

const MAX_X = 200010

func solve(n int, segs [][]int) int {
	lines := make([]Line, n, n+1)
	for i := 0; i < n; i++ {
		lines[i] = Line{segs[i][0], segs[i][1]}
	}
	lines = append(lines, Line{1, MAX_X})
	sort.Sort(Lines(lines))
	n++

	G := make([][]int, n)

	for i := 0; i < n; i++ {
		G[i] = make([]int, 0, 10)
	}

	check := func(i, j int) bool {
		a, b := lines[i], lines[j]
		return a.l <= b.l && b.r <= a.r
	}

	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			if check(i, j) {
				G[i] = append(G[i], j)
			}
		}
	}

	dp := make([]int, n)
	var dfs func(u int) int

	dfs = func(u int) int {
		if dp[u] != 0 {
			return dp[u]
		}
		if len(G[u]) == 0 {
			dp[u] = 1
			return 1
		}
		root := NewNode(lines[u].l, lines[u].r, 0)
		var best int
		for _, v := range G[u] {
			tmp := dfs(v)
			cur := lines[v]
			x := root.FindMaxBefore(cur.l-1, lines[u].l, lines[u].r)
			if x+tmp > best {
				best = x + tmp
			}
			root = root.Insert(cur.r, x+tmp, lines[u].l, lines[u].r)
		}

		best++

		dp[u] = best

		return best
	}
	res := dfs(0)

	return res - 1
}

type Node struct {
	left, right *Node
	start, end  int
	maxValue    int
}

func NewNode(start, end, val int) *Node {
	node := new(Node)
	node.start = start
	node.end = end
	node.maxValue = val
	return node
}

func (node *Node) Insert(p, v int, start, end int) *Node {
	if node == nil {
		node = NewNode(start, end, v)
	}
	if node.start == node.end {
		return node
	}
	mid := (node.start + node.end) / 2
	if p <= mid {
		node.left = node.left.Insert(p, v, start, mid)
	} else {
		node.right = node.right.Insert(p, v, mid+1, end)
	}
	if node.left == nil {
		node.maxValue = node.right.maxValue
	} else if node.right == nil {
		node.maxValue = node.left.maxValue
	} else {
		node.maxValue = max(node.left.maxValue, node.right.maxValue)
	}

	return node
}

func (node *Node) FindMaxBefore(p int, start, end int) int {
	if node == nil {
		return 0
	}
	if node.start == node.end {
		return node.maxValue
	}
	mid := (node.start + node.end) / 2
	if p <= mid {
		return node.left.FindMaxBefore(p, start, mid)
	}
	res := node.right.FindMaxBefore(p, mid+1, end)
	if node.left != nil {
		return max(node.left.maxValue, res)
	}
	return res
}

func max(a, b int) int {
	if a >= b {
		return a
	}
	return b
}

type Line struct {
	l, r int
}

type Lines []Line

func (lines Lines) Len() int {
	return len(lines)
}

func (lines Lines) Less(i, j int) bool {
	return lines[i].l < lines[j].l || lines[i].l == lines[j].l && lines[i].r > lines[j].r
}

func (lines Lines) Swap(i, j int) {
	lines[i], lines[j] = lines[j], lines[i]
}