package main

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

var (
	in  = bufio.NewReader(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
)

func flush()                            { out.Flush() }
func scan(a ...interface{})             { fmt.Fscan(in, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(out, f, a...) }

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func unique(a []int) []int {
	j := 1
	for i := 1; i < len(a); i++ {
		if a[i] != a[i-1] {
			a[j] = a[i]
			j++
		}
	}
	return a[:j]
}

// ----------------------------- TEMPLATE END ----------------------------------

type SpanningTree struct {
	id          []int   // edge IDs
	w           []int   // edge weights
	wacc        []int64 // wacc[i] = w[i]+w[i+1]+...
	optimalFrom int
}

type Edge struct {
	id int
	a  int
	b  int
	c  int
	c1 int
}

type DisjointSet struct {
	p []int
}

func (dset *DisjointSet) root(a int) int {
	if dset.p[a] != a {
		dset.p[a] = dset.root(dset.p[a])
	}
	return dset.p[a]
}

func (dset *DisjointSet) join(a, b int) {
	a = dset.root(a)
	b = dset.root(b)
	dset.p[b] = a
}

func (dset *DisjointSet) clear() {
	n := len(dset.p)
	for i := 0; i < n; i++ {
		dset.p[i] = i
	}
}

func newDisjoinSet(n int) *DisjointSet {
	r := &DisjointSet{
		p: make([]int, n),
	}
	for i := 0; i < n; i++ {
		r.p[i] = i
	}
	return r
}

func newSpanningTree(n int) *SpanningTree {
	return &SpanningTree{
		w:           make([]int, n-1),
		id:          make([]int, n-1),
		wacc:        make([]int64, n),
		optimalFrom: 0,
	}
}

func fillSpanningTreeAcc(r *SpanningTree) {
	sort.Slice(r.w, func(i, j int) bool {
		return r.w[i] < r.w[j]
	})
	r.wacc[n-1] = 0
	for i := n - 2; i >= 0; i-- {
		r.wacc[i] = r.wacc[i+1] + int64(r.w[i])
	}
}

const INF = int64(1e12)

var n, nEdges int
var edges []*Edge

var mst *SpanningTree
var dset *DisjointSet

func kruskal(x int) {
	for i := 0; i < nEdges; i++ {
		edges[i].c1 = abs(edges[i].c - x)
	}
	sort.Slice(edges, func(i, j int) bool {
		if edges[i].c1 != edges[j].c1 {
			return edges[i].c1 < edges[j].c1
		}
		return edges[i].id < edges[j].id
	})

	dset.clear()
	mstIndex := 0
	for _, e := range edges {
		if dset.root(e.a) == dset.root(e.b) {
			continue
		}
		mst.id[mstIndex] = e.id
		mst.w[mstIndex] = e.c
		mstIndex++
		dset.join(e.a, e.b)
		if mstIndex == n-1 {
			break
		}
	}
}

func sameSpanningTree(a, b *SpanningTree) bool {
	for i := 0; i < n-1; i++ {
		if a.id[i] != b.id[i] {
			return false
		}
	}
	return true
}

func calc(st *SpanningTree, x int) int64 {
	lo := 0
	hi := n - 1
	mi := 0
	for lo < hi {
		mi = (lo + hi) / 2
		if st.w[mi] <= x {
			lo = mi + 1
		} else {
			hi = mi
		}
	}
	// printf("x=%d, st: %v. lo=%d\n", x, st.w, lo)
	return (st.wacc[lo] - int64(n-1-lo)*int64(x)) + int64(lo)*int64(x) - (st.wacc[0] - st.wacc[lo])
}

func main() {
	defer flush()

	scan(&n, &nEdges)
	edges = make([]*Edge, nEdges)
	mst = newSpanningTree(n)
	dset = newDisjoinSet(n)
	for i := 0; i < nEdges; i++ {
		edges[i] = &Edge{}
		scan(&edges[i].a, &edges[i].b, &edges[i].c)
		edges[i].id = i
		edges[i].a--
		edges[i].b--
	}

	var importantXs []int = []int{0}
	for i := 0; i < nEdges; i++ {
		for j := i + 1; j < nEdges; j++ {
			half := (edges[i].c + edges[j].c) / 2
			importantXs = append(importantXs, half)
			importantXs = append(importantXs, half+1)
			if edges[i].c%2 == edges[j].c%2 {
				importantXs = append(importantXs, half-1)
			}
		}
	}

	sort.Slice(importantXs, func(i, j int) bool {
		return importantXs[i] < importantXs[j]
	})
	importantXs = unique(importantXs)

	// printf("important weights = %v\n", importantXs)

	var explicitQueries, totalQueries int
	var currentQ, queryA, queryB, queryMod int64
	var ansXor int64 = 0
	scan(&explicitQueries, &totalQueries)
	scan(&queryA, &queryB, &queryMod)
	// printf("explicit = %d, total=%d\n", explicitQueries, totalQueries)
	var queries []int = make([]int, totalQueries)
	for i := 0; i < explicitQueries; i++ {
		scan(&currentQ)
		queries[i] = int(currentQ)
	}
	for i := explicitQueries; i < totalQueries; i++ {
		currentQ = (currentQ*queryA + queryB) % queryMod
		queries[i] = int(currentQ)
	}

	var i int = 0
	kruskal(0)
	var optimal = newSpanningTree(n)
	optimal, mst = mst, optimal
	fillSpanningTreeAcc(optimal)

	sort.Ints(queries)
	for _, q := range queries {
		j := i
		for j+1 < len(importantXs) && importantXs[j+1] <= q {
			j++
		}
		if j != i {
			kruskal(importantXs[j])
			if !sameSpanningTree(optimal, mst) {
				optimal, mst = mst, optimal
				fillSpanningTreeAcc(optimal)
			}
			i = j
		}
		ansq := calc(optimal, q)
		// printf("answer(%d) = %d. x=%d\n", q, ansq, importantXs[i])
		ansXor ^= ansq
	}
	printf("%d\n", ansXor)
}

package main

import (
	//"bufio"
	"fmt"
	//"os"
	"sort"
	"math/rand"
	"time"
	"bufio"
	"os"
	"strconv"
)

var n, m int

var p,k,a,b, c int64

var qu []int64

type edge struct {
	from, to int
	w int64
}

var e []*edge

type ByW []*edge

func (a ByW) Len() int           { return len(a) }
func (a ByW) Less(i, j int) bool { return a[i].w < a[j].w }
func (a ByW) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

var r *bufio.Reader

const WRITE = false

func main() {

	rand.Seed(time.Now().UnixNano())
	f, _ := os.OpenFile("D:\\GO\\src\\codeforces\\edu122\\5\\in.txt", os.O_RDWR, 0)
	defer f.Close()

	if WRITE {

		for i := 0; i < 100; i++ {
			n = 5
			m = 10

			f.WriteString("5 10\n")

			for j := 0; j < m; j++ {
				var from, to, w int
				from = 1 + rand.Intn(n)
				for ;; {
					to = 1 + rand.Intn(n)
					if to != from {
						break
					}
				}
				w = 1 + rand.Intn(1e2)

				f.WriteString(strconv.Itoa(from))
				f.WriteString(" ")
				f.WriteString(strconv.Itoa(to))
				f.WriteString(" ")
				f.WriteString(strconv.Itoa(w))
				f.WriteString("\n")
			}

			//p = 10
			//k = 100
			//a = 1
			//b = 1
			//c = 100

			f.WriteString("5 10 7 13 100\n")

			for j := 1; j <= 5; j++ {
				x := rand.Intn(1e2)
				f.WriteString(strconv.Itoa(x))
				f.WriteString(" ")
			}

			f.WriteString("\n")
		}

		return
	}

	r = bufio.NewReader(os.Stdin)

	fmt.Fscan(r, &n, &m)

	e = make([]*edge, m)

	for i := 0; i < m; i++ {
		var from, to int
		var w int64
		fmt.Fscan(r, &from)
		fmt.Fscan(r, &to)
		fmt.Fscan(r, &w)

		from--
		to--

		ed := &edge{from, to, w}
		e[i] = ed
	}

	fmt.Fscan(r, &p, &k, &a, &b, &c)

	qu = make([]int64, p)

	for i := 0; i < int(p); i++ {
		var x int64
		fmt.Fscan(r, &x)
		qu[i] = x
	}

	//	st := time.Now().UnixNano()

	ans := solve()

	//	en := time.Now().UnixNano()
	//
	//	fmt.Println((en - st)/1000000)

	fmt.Println(ans)

}

type pair struct {
	v, id int
}

type ByV []*pair

func (a ByV) Len() int           { return len(a) }
func (a ByV) Less(i, j int) bool { return a[i].v < a[j].v }
func (a ByV) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

type item struct {
	la, ra int
	lb, rb int
}

const MAX int = 1e6
var cost []int

const INF = int(1e9) + 5;

type value struct {
	l, r int
	val int64
}

func solve_stupid() int64 {
	var xMax int64 = 1000

	ans := make([]int64, xMax + 1)

	var x int64
	for x = 0; x <= xMax; x++ {
		sum := computeMST(x)
		ans[x] = sum
	}

	var aa int64

	var xIn int64

	var i int64
	for i = 0; i < p; i++ {
		xIn = qu[i]

		aa = aa ^ ans[xIn]
	}

	for i := p; i < k; i++ {
		xIn = (xIn * a + b) % c

		aa = aa ^ ans[xIn]
	}

	return aa

}

//71 55 109 45 125 69 35 66 125 69
//21 55 109 45 125 69 35 66 125 69
//71 55 109 45 125 69 35 66 125 69

func computeMST(x int64) int64 {
	e2 := make([]*edge, m)

	for i := 0; i < m; i++ {
		ed := e[i]

		ed2 := edge{ed.from, ed.to, abs(ed.w - x)}

		e2[i] = &ed2
	}

	sort.Sort(ByW(e2))

	parent := make([]int, n)
	rank := make([]int, n)

	for i := 0; i < n; i++ {
		parent[i] = i
		rank[i] = 0
	}

	var sum int64

	for i := 0; i < m;  i++ {
		ed := e2[i]

		a := ed.from
		b := ed.to

		rootA := find(&parent, a)
		rootB := find(&parent, b)

		if rootA==rootB {
			continue
		}

		sum += int64(abs(ed.w))

		if  (rank)[rootA] < (rank)[rootB]{
			(parent)[rootA] = rootB

		} else if (rank)[rootA] > (rank)[rootB] {
			(parent)[rootB] = rootA

		} else {
			(parent)[rootB] = rootA
			(rank)[rootA]++
		}
	}

	return sum

}

func solve() int64 {
	sort.Sort(ByW(e))

	mp := make(map[int64]int)

	for i := 0; i < len(e); i++ {
		w1 := e[i].w
		for j := i + 1; j < len(e); j++ {
			w2 := e[j].w

			//5 6 7 8 9 10 11 12
			//3 4 5 6 7 8 9 10 11 12

			if w2 > w1 {
				key := (w1 + w2)/2 + 1
				mp[int64(key)] = 0
			}
		}
	}
	for i := 0; i < len(e); i++ {
		w := e[i].w
		mp[int64(w)] = 1
	}

	tree := newInt64InterfaceTreeMap(func(a int64, b int64) bool {
		return a < b
	})

	aa := doCompute(0)
	tree.Set(0, aa)

	for k, _ := range mp {
		ans := doCompute(k)

		tree.Set(k, ans)
	}

	var ans int64

	var x int64

	var i int64
	for i = 0; i < p; i++ {
		x = qu[i]

		lb := tree.LowerBound(x)

		if lb.Key() == x {
			ans = ans ^ lb.Value().(*value).val
			continue
		}

		lb.Prev()

		k := lb.Key()

		left := lb.Value().(*value).l
		right := lb.Value().(*value).r
		val := lb.Value().(*value).val

		res := val + int64(left) * int64(x - k) - int64(right) * int64(x - k)

		ans = ans ^ res

	}

	for i := p; i < k; i++ {
		x = (x * a + b) % c

		lb := tree.LowerBound(x)

		if lb.Key() == x {
			ans = ans ^ lb.Value().(*value).val
			continue
		}

		lb.Prev()

		k := lb.Key()

		left := lb.Value().(*value).l
		right := lb.Value().(*value).r
		val := lb.Value().(*value).val

		res := val + int64(left) * int64(x - k) - int64(right) * int64(x - k)
		ans = ans ^ res
	}

	return ans
}

func doCompute(x int64) *value {
	parent := make([]int, n)
	rank := make([]int, n)

	for i := 0; i < n; i++ {
		parent[i] = i
		rank[i] = 0
	}

	idx := sort.Search(m, func(i int) bool {
		ed := e[i]
		return ed.w > x
	})

	var ans *value

	if idx == 0 {
		ans = goFromStart(&parent, &rank, x)

	} else if idx == m {
		ans = goFromEnd(&parent, &rank, x)

	} else {
		ans = goFrom(idx, &parent, &rank, x)
	}

	return ans
}

func find(parent *[]int, p int) int {
	for ; p != (*parent)[p]; {
		(*parent)[p] = (*parent)[(*parent)[p]]
		p = (*parent)[p]
	}

	return p
}

func goFromStart(parent *[]int, rank *[]int, x int64) *value {

	sum := &value{}

	for i := 0; i < m;  i++ {
		ed := e[i]

		a := ed.from
		b := ed.to

		rootA := find(parent, a)
		rootB := find(parent, b)

		if rootA==rootB {
			continue
		}

		sum.val += int64(abs(ed.w - x))
		sum.r++

		if  (*rank)[rootA] < (*rank)[rootB]{
			(*parent)[rootA] = rootB

		} else if (*rank)[rootA] > (*rank)[rootB] {
			(*parent)[rootB] = rootA

		} else {
			(*parent)[rootB] = rootA
			(*rank)[rootA]++
		}
	}

	return sum
}

func goFromEnd(parent *[]int, rank *[]int, x int64) *value {

	sum := &value{}

	for i := m - 1; i >= 0;  i-- {
		ed := e[i]

		a := ed.from
		b := ed.to

		rootA := find(parent, a)
		rootB := find(parent, b)

		if rootA==rootB {
			continue
		}

		sum.val += int64(abs(ed.w - x))
		sum.l++

		if  (*rank)[rootA] < (*rank)[rootB]{
			(*parent)[rootA] = rootB

		} else if (*rank)[rootA] > (*rank)[rootB] {
			(*parent)[rootB] = rootA

		} else {
			(*parent)[rootB] = rootA
			(*rank)[rootA]++
		}
	}

	return sum
}

func goFrom(idx int, parent *[]int, rank *[]int, x int64) *value {
	sum := &value{}

	var i, j int

	i = idx
	j = idx - 1

	for ; j >= 0 && i < m; {
		e1 := e[i]
		e2 := e[j]

		if abs(e1.w - x) <= abs(e2.w - x) {
			//e1
			a := e1.from
			b := e1.to

			rootA := find(parent, a)
			rootB := find(parent, b)

			if rootA==rootB {
				i++
				continue
			}

			sum.r++
			sum.val += int64(abs(e1.w - x))

			if  (*rank)[rootA] < (*rank)[rootB]{
				(*parent)[rootA] = rootB

			} else if (*rank)[rootA] > (*rank)[rootB] {
				(*parent)[rootB] = rootA

			} else {
				(*parent)[rootB] = rootA
				(*rank)[rootA]++
			}

			i++
		} else {
			//e2
			a := e2.from
			b := e2.to

			rootA := find(parent, a)
			rootB := find(parent, b)

			if rootA==rootB {
				j--
				continue
			}

			sum.l++
			sum.val += int64(abs(e2.w - x))

			if  (*rank)[rootA] < (*rank)[rootB]{
				(*parent)[rootA] = rootB

			} else if (*rank)[rootA] > (*rank)[rootB] {
				(*parent)[rootB] = rootA

			} else {
				(*parent)[rootB] = rootA
				(*rank)[rootA]++
			}

			j--
		}
	}

	for k := j; k >= 0; k-- {
		ed := e[k]

		a := ed.from
		b := ed.to

		rootA := find(parent, a)
		rootB := find(parent, b)

		if rootA == rootB {
			continue
		}

		sum.val += int64(abs(ed.w - x))
		sum.l++

		if (*rank)[rootA] < (*rank)[rootB] {
			(*parent)[rootA] = rootB

		} else if (*rank)[rootA] > (*rank)[rootB] {
			(*parent)[rootB] = rootA

		} else {
			(*parent)[rootB] = rootA
			(*rank)[rootA]++
		}

	}

	for k := i; k < m; k++ {
		ed := e[k]

		a := ed.from
		b := ed.to

		rootA := find(parent, a)
		rootB := find(parent, b)

		if rootA == rootB {
			continue
		}

		sum.val += int64(abs(ed.w - x))
		sum.r++

		if (*rank)[rootA] < (*rank)[rootB] {
			(*parent)[rootA] = rootB

		} else if (*rank)[rootA] > (*rank)[rootB] {
			(*parent)[rootB] = rootA

		} else {
			(*parent)[rootB] = rootA
			(*rank)[rootA]++
		}
	}

	return sum
}

func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

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

func add(idx int, delta int, bit *[]int, n int) {
	for ; idx <= n; idx += idx & -idx {
		(*bit)[idx] += delta
	}
}

func get(idx int, bit *[]int) int {
	ret := 0
	for ; idx > 0; idx -= idx & -idx {
		ret += (*bit)[idx];
	}
	return ret
}

//A -  1 3 5 3 1

//B -  4 3 6 1

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

type int64InterfaceTreeMap struct {
	endNode   *nodeInt64InterfaceTreeMap
	beginNode *nodeInt64InterfaceTreeMap
	count     int
	// Less returns a < b
	Less func(a int64, b int64) bool
}

type nodeInt64InterfaceTreeMap struct {
	right   *nodeInt64InterfaceTreeMap
	left    *nodeInt64InterfaceTreeMap
	parent  *nodeInt64InterfaceTreeMap
	isBlack bool
	key     int64
	value   interface{}
}

// New creates and returns new TreeMap.
// Parameter less is a function returning a < b.
func newInt64InterfaceTreeMap(less func(a int64, b int64) bool) *int64InterfaceTreeMap {
	endNode := &nodeInt64InterfaceTreeMap{isBlack: true}
	return &int64InterfaceTreeMap{beginNode: endNode, endNode: endNode, Less: less}
}

// Len returns total count of elements in a map.
// Complexity: O(1).
func (t *int64InterfaceTreeMap) Len() int { return t.count }

// Set sets the value and silently overrides previous value if it exists.
// Complexity: O(log N).
func (t *int64InterfaceTreeMap) Set(key int64, value interface{}) {
	parent := t.endNode
	current := parent.left
	less := true
	for current != nil {
		parent = current
		switch {
		case t.Less(key, current.key):
			current = current.left
			less = true
		case t.Less(current.key, key):
			current = current.right
			less = false
		default:
			current.value = value
			return
		}
	}
	x := &nodeInt64InterfaceTreeMap{parent: parent, value: value, key: key}
	if less {
		parent.left = x
	} else {
		parent.right = x
	}
	if t.beginNode.left != nil {
		t.beginNode = t.beginNode.left
	}
	t.insertFixup(x)
	t.count++
}

// Del deletes the value.
// Complexity: O(log N).
func (t *int64InterfaceTreeMap) Del(key int64) {
	z := t.findNode(key)
	if z == nil {
		return
	}
	if t.beginNode == z {
		if z.right != nil {
			t.beginNode = z.right
		} else {
			t.beginNode = z.parent
		}
	}
	t.count--
	removeNodeInt64InterfaceTreeMap(t.endNode.left, z)
}

// Clear clears the map.
// Complexity: O(1).
func (t *int64InterfaceTreeMap) Clear() {
	t.count = 0
	t.beginNode = t.endNode
	t.endNode.left = nil
}

// Get retrieves a value from a map for specified key and reports if it exists.
// Complexity: O(log N).
func (t *int64InterfaceTreeMap) Get(id int64) (interface{}, bool) {
	node := t.findNode(id)
	if node == nil {
		node = t.endNode
	}
	return node.value, node != t.endNode
}

// Contains checks if key exists in a map.
// Complexity: O(log N)
func (t *int64InterfaceTreeMap) Contains(id int64) bool { return t.findNode(id) != nil }

// Range returns a pair of iterators that you can use to go through all the keys in the range [from, to].
// More specifically it returns iterators pointing to lower bound and upper bound.
// Complexity: O(log N).
func (t *int64InterfaceTreeMap) Range(from, to int64) (forwardIteratorInt64InterfaceTreeMap, forwardIteratorInt64InterfaceTreeMap) {
	return t.LowerBound(from), t.UpperBound(to)
}

// LowerBound returns an iterator pointing to the first element that is not less than the given key.
// Complexity: O(log N).
func (t *int64InterfaceTreeMap) LowerBound(key int64) forwardIteratorInt64InterfaceTreeMap {
	result := t.endNode
	node := t.endNode.left
	if node == nil {
		return forwardIteratorInt64InterfaceTreeMap{tree: t, node: t.endNode}
	}
	for {
		if t.Less(node.key, key) {
			if node.right != nil {
				node = node.right
			} else {
				return forwardIteratorInt64InterfaceTreeMap{tree: t, node: result}
			}
		} else {
			result = node
			if node.left != nil {
				node = node.left
			} else {
				return forwardIteratorInt64InterfaceTreeMap{tree: t, node: result}
			}
		}
	}
}

// UpperBound returns an iterator pointing to the first element that is greater than the given key.
// Complexity: O(log N).
func (t *int64InterfaceTreeMap) UpperBound(key int64) forwardIteratorInt64InterfaceTreeMap {
	result := t.endNode
	node := t.endNode.left
	if node == nil {
		return forwardIteratorInt64InterfaceTreeMap{tree: t, node: t.endNode}
	}
	for {
		if !t.Less(key, node.key) {
			if node.right != nil {
				node = node.right
			} else {
				return forwardIteratorInt64InterfaceTreeMap{tree: t, node: result}
			}
		} else {
			result = node
			if node.left != nil {
				node = node.left
			} else {
				return forwardIteratorInt64InterfaceTreeMap{tree: t, node: result}
			}
		}
	}
}

// Iterator returns an iterator for tree map.
// It starts at the first element and goes to the one-past-the-end position.
// You can iterate a map at O(N) complexity.
// Method complexity: O(1)
func (t *int64InterfaceTreeMap) Iterator() forwardIteratorInt64InterfaceTreeMap {
	return forwardIteratorInt64InterfaceTreeMap{tree: t, node: t.beginNode}
}

// Reverse returns a reverse iterator for tree map.
// It starts at the last element and goes to the one-before-the-start position.
// You can iterate a map at O(N) complexity.
// Method complexity: O(log N)
func (t *int64InterfaceTreeMap) Reverse() reverseIteratorInt64InterfaceTreeMap {
	node := t.endNode.left
	if node != nil {
		node = mostRightInt64InterfaceTreeMap(node)
	}
	return reverseIteratorInt64InterfaceTreeMap{tree: t, node: node}
}

func (t *int64InterfaceTreeMap) findNode(id int64) *nodeInt64InterfaceTreeMap {
	current := t.endNode.left
	for current != nil {
		switch {
		case t.Less(id, current.key):
			current = current.left
		case t.Less(current.key, id):
			current = current.right
		default:
			return current
		}
	}
	return nil
}

func mostLeftInt64InterfaceTreeMap(x *nodeInt64InterfaceTreeMap) *nodeInt64InterfaceTreeMap {
	for x.left != nil {
		x = x.left
	}
	return x
}

func mostRightInt64InterfaceTreeMap(x *nodeInt64InterfaceTreeMap) *nodeInt64InterfaceTreeMap {
	for x.right != nil {
		x = x.right
	}
	return x
}

func successorInt64InterfaceTreeMap(x *nodeInt64InterfaceTreeMap) *nodeInt64InterfaceTreeMap {
	if x.right != nil {
		return mostLeftInt64InterfaceTreeMap(x.right)
	}
	for x != x.parent.left {
		x = x.parent
	}
	return x.parent
}

func predecessorInt64InterfaceTreeMap(x *nodeInt64InterfaceTreeMap) *nodeInt64InterfaceTreeMap {
	if x.left != nil {
		return mostRightInt64InterfaceTreeMap(x.left)
	}
	for x.parent != nil && x != x.parent.right {
		x = x.parent
	}
	return x.parent
}

func rotateLeftInt64InterfaceTreeMap(x *nodeInt64InterfaceTreeMap) {
	y := x.right
	x.right = y.left
	if x.right != nil {
		x.right.parent = x
	}
	y.parent = x.parent
	if x == x.parent.left {
		x.parent.left = y
	} else {
		x.parent.right = y
	}
	y.left = x
	x.parent = y
}

func rotateRightInt64InterfaceTreeMap(x *nodeInt64InterfaceTreeMap) {
	y := x.left
	x.left = y.right
	if x.left != nil {
		x.left.parent = x
	}
	y.parent = x.parent
	if x == x.parent.left {
		x.parent.left = y
	} else {
		x.parent.right = y
	}
	y.right = x
	x.parent = y
}

func (t *int64InterfaceTreeMap) insertFixup(x *nodeInt64InterfaceTreeMap) {
	root := t.endNode.left
	x.isBlack = x == root
	for x != root && !x.parent.isBlack {
		if x.parent == x.parent.parent.left {
			y := x.parent.parent.right
			if y != nil && !y.isBlack {
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = x == root
				y.isBlack = true
			} else {
				if x != x.parent.left {
					x = x.parent
					rotateLeftInt64InterfaceTreeMap(x)
				}
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = false
				rotateRightInt64InterfaceTreeMap(x)
				break
			}
		} else {
			y := x.parent.parent.left
			if y != nil && !y.isBlack {
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = x == root
				y.isBlack = true
			} else {
				if x == x.parent.left {
					x = x.parent
					rotateRightInt64InterfaceTreeMap(x)
				}
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = false
				rotateLeftInt64InterfaceTreeMap(x)
				break
			}
		}
	}
}

// nolint: gocyclo
//noinspection GoNilness
func removeNodeInt64InterfaceTreeMap(root *nodeInt64InterfaceTreeMap, z *nodeInt64InterfaceTreeMap) {
	var y *nodeInt64InterfaceTreeMap
	if z.left == nil || z.right == nil {
		y = z
	} else {
		y = successorInt64InterfaceTreeMap(z)
	}
	var x *nodeInt64InterfaceTreeMap
	if y.left != nil {
		x = y.left
	} else {
		x = y.right
	}
	var w *nodeInt64InterfaceTreeMap
	if x != nil {
		x.parent = y.parent
	}
	if y == y.parent.left {
		y.parent.left = x
		if y != root {
			w = y.parent.right
		} else {
			root = x // w == nil
		}
	} else {
		y.parent.right = x
		w = y.parent.left
	}
	removedBlack := y.isBlack
	if y != z {
		y.parent = z.parent
		if z == z.parent.left {
			y.parent.left = y
		} else {
			y.parent.right = y
		}
		y.left = z.left
		y.left.parent = y
		y.right = z.right
		if y.right != nil {
			y.right.parent = y
		}
		y.isBlack = z.isBlack
		if root == z {
			root = y
		}
	}
	if removedBlack && root != nil {
		if x != nil {
			x.isBlack = true
		} else {
			for {
				if w != w.parent.left {
					if !w.isBlack {
						w.isBlack = true
						w.parent.isBlack = false
						rotateLeftInt64InterfaceTreeMap(w.parent)
						if root == w.left {
							root = w
						}
						w = w.left.right
					}
					if (w.left == nil || w.left.isBlack) && (w.right == nil || w.right.isBlack) {
						w.isBlack = false
						x = w.parent
						if x == root || !x.isBlack {
							x.isBlack = true
							break
						}
						if x == x.parent.left {
							w = x.parent.right
						} else {
							w = x.parent.left
						}
					} else {
						if w.right == nil || w.right.isBlack {
							w.left.isBlack = true
							w.isBlack = false
							rotateRightInt64InterfaceTreeMap(w)
							w = w.parent
						}
						w.isBlack = w.parent.isBlack
						w.parent.isBlack = true
						w.right.isBlack = true
						rotateLeftInt64InterfaceTreeMap(w.parent)
						break
					}
				} else {
					if !w.isBlack {
						w.isBlack = true
						w.parent.isBlack = false
						rotateRightInt64InterfaceTreeMap(w.parent)
						if root == w.right {
							root = w
						}
						w = w.right.left
					}
					if (w.left == nil || w.left.isBlack) && (w.right == nil || w.right.isBlack) {
						w.isBlack = false
						x = w.parent
						if !x.isBlack || x == root {
							x.isBlack = true
							break
						}
						if x == x.parent.left {
							w = x.parent.right
						} else {
							w = x.parent.left
						}
					} else {
						if w.left == nil || w.left.isBlack {
							w.right.isBlack = true
							w.isBlack = false
							rotateLeftInt64InterfaceTreeMap(w)
							w = w.parent
						}
						w.isBlack = w.parent.isBlack
						w.parent.isBlack = true
						w.left.isBlack = true
						rotateRightInt64InterfaceTreeMap(w.parent)
						break
					}
				}
			}
		}
	}
}

// ForwardIterator represents a position in a tree map.
// It is designed to iterate a map in a forward order.
// It can point to any position from the first element to the one-past-the-end element.
type forwardIteratorInt64InterfaceTreeMap struct {
	tree *int64InterfaceTreeMap
	node *nodeInt64InterfaceTreeMap
}

// Valid reports if an iterator's position is valid.
// In other words it returns true if an iterator is not at the one-past-the-end position.
func (i forwardIteratorInt64InterfaceTreeMap) Valid() bool { return i.node != i.tree.endNode }

// Next moves an iterator to the next element.
// It panics if goes out of bounds.
func (i *forwardIteratorInt64InterfaceTreeMap) Next() {
	if i.node == i.tree.endNode {
		panic("out of bound iteration")
	}
	i.node = successorInt64InterfaceTreeMap(i.node)
}

// Prev moves an iterator to the previous element.
// It panics if goes out of bounds.
func (i *forwardIteratorInt64InterfaceTreeMap) Prev() {
	i.node = predecessorInt64InterfaceTreeMap(i.node)
	if i.node == nil {
		panic("out of bound iteration")
	}
}

// Key returns a key at an iterator's position
func (i forwardIteratorInt64InterfaceTreeMap) Key() int64 { return i.node.key }

// Value returns a value at an iterator's position
func (i forwardIteratorInt64InterfaceTreeMap) Value() interface{} { return i.node.value }

// ReverseIterator represents a position in a tree map.
// It is designed to iterate a map in a reverse order.
// It can point to any position from the one-before-the-start element to the last element.
type reverseIteratorInt64InterfaceTreeMap struct {
	tree *int64InterfaceTreeMap
	node *nodeInt64InterfaceTreeMap
}

// Valid reports if an iterator's position is valid.
// In other words it returns true if an iterator is not at the one-before-the-start position.
func (i reverseIteratorInt64InterfaceTreeMap) Valid() bool { return i.node != nil }

// Next moves an iterator to the next element in reverse order.
// It panics if goes out of bounds.
func (i *reverseIteratorInt64InterfaceTreeMap) Next() {
	if i.node == nil {
		panic("out of bound iteration")
	}
	i.node = predecessorInt64InterfaceTreeMap(i.node)
}

// Prev moves an iterator to the previous element in reverse order.
// It panics if goes out of bounds.
func (i *reverseIteratorInt64InterfaceTreeMap) Prev() {
	if i.node != nil {
		i.node = successorInt64InterfaceTreeMap(i.node)
	} else {
		i.node = i.tree.beginNode
	}
	if i.node == i.tree.endNode {
		panic("out of bound iteration")
	}
}

// Key returns a key at an iterator's position
func (i reverseIteratorInt64InterfaceTreeMap) Key() int64 { return i.node.key }

// Value returns a value at an iterator's position
func (i reverseIteratorInt64InterfaceTreeMap) Value() interface{} { return i.node.value }

package main

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

var (
	in  = bufio.NewReader(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
)

func flush()                            { out.Flush() }
func scan(a ...interface{})             { fmt.Fscan(in, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(out, f, a...) }

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func unique(a []int) []int {
	j := 1
	for i := 1; i < len(a); i++ {
		if a[i] != a[i-1] {
			a[j] = a[i]
			j++
		}
	}
	return a[:j]
}

// ----------------------------- TEMPLATE END ----------------------------------

type SpanningTree struct {
	id          []int   // edge IDs
	w           []int   // edge weights
	wacc        []int64 // wacc[i] = w[i]+w[i+1]+...
	optimalFrom int
}

type Edge struct {
	id int
	a  int
	b  int
	c  int
	c1 int
}

type DisjointSet struct {
	p []int
}

func (dset *DisjointSet) root(a int) int {
	if dset.p[a] != a {
		dset.p[a] = dset.root(dset.p[a])
	}
	return dset.p[a]
}

func (dset *DisjointSet) join(a, b int) {
	a = dset.root(a)
	b = dset.root(b)
	dset.p[b] = a
}

func (dset *DisjointSet) clear() {
	n := len(dset.p)
	for i := 0; i < n; i++ {
		dset.p[i] = i
	}
}

func newDisjoinSet(n int) *DisjointSet {
	r := &DisjointSet{
		p: make([]int, n),
	}
	for i := 0; i < n; i++ {
		r.p[i] = i
	}
	return r
}

func newSpanningTree(n int) *SpanningTree {
	return &SpanningTree{
		w:           make([]int, n-1),
		id:          make([]int, n-1),
		wacc:        make([]int64, n),
		optimalFrom: 0,
	}
}

func fillSpanningTreeAcc(r *SpanningTree) {
	sort.Slice(r.w, func(i, j int) bool {
		return r.w[i] < r.w[j]
	})
	r.wacc[n-1] = 0
	for i := n - 2; i >= 0; i-- {
		r.wacc[i] = r.wacc[i+1] + int64(r.w[i])
	}
}

const INF = int64(1e12)

var n, nEdges int
var edges []*Edge

var mst *SpanningTree
var dset *DisjointSet

func kruskal(x int) {
	for i := 0; i < nEdges; i++ {
		edges[i].c1 = abs(edges[i].c - x)
	}
	sort.Slice(edges, func(i, j int) bool {
		if edges[i].c1 != edges[j].c1 {
			return edges[i].c1 < edges[j].c1
		}
		return edges[i].id < edges[j].id
	})

	dset.clear()
	mstIndex := 0
	for _, e := range edges {
		if dset.root(e.a) == dset.root(e.b) {
			continue
		}
		mst.id[mstIndex] = e.id
		mst.w[mstIndex] = e.c
		mstIndex++
		dset.join(e.a, e.b)
		if mstIndex == n-1 {
			break
		}
	}
}

func calc(st *SpanningTree, x int) int64 {
	lo := 0
	hi := n - 1
	mi := 0
	for lo < hi {
		mi = (lo + hi) / 2
		if st.w[mi] <= x {
			lo = mi + 1
		} else {
			hi = mi
		}
	}
	// printf("x=%d, st: %v. lo=%d\n", x, st.w, lo)
	return (st.wacc[lo] - int64(n-1-lo)*int64(x)) + int64(lo)*int64(x) - (st.wacc[0] - st.wacc[lo])
}

func main() {
	defer flush()

	scan(&n, &nEdges)
	edges = make([]*Edge, nEdges)
	mst = newSpanningTree(n)
	dset = newDisjoinSet(n)
	for i := 0; i < nEdges; i++ {
		edges[i] = &Edge{}
		scan(&edges[i].a, &edges[i].b, &edges[i].c)
		edges[i].id = i
		edges[i].a--
		edges[i].b--
	}

	var importantXs []int = []int{0}
	for i := 0; i < nEdges; i++ {
		for j := i + 1; j < nEdges; j++ {
			half := (edges[i].c + edges[j].c) / 2
			if edges[i].c%2 == edges[j].c%2 {
				importantXs = append(importantXs, half)
				importantXs = append(importantXs, half-1)
			} else {
				importantXs = append(importantXs, half)
				importantXs = append(importantXs, half+1)
			}
		}
	}

	sort.Slice(importantXs, func(i, j int) bool {
		return importantXs[i] < importantXs[j]
	})
	importantXs = unique(importantXs)

	var explicitQueries, totalQueries int
	var currentQ, queryA, queryB, queryMod int64
	var ansXor int64 = 0
	scan(&explicitQueries, &totalQueries)
	scan(&queryA, &queryB, &queryMod)

	var queries []int = make([]int, totalQueries)
	for i := 0; i < explicitQueries; i++ {
		scan(&currentQ)
		queries[i] = int(currentQ)
	}
	for i := explicitQueries; i < totalQueries; i++ {
		currentQ = (currentQ*queryA + queryB) % queryMod
		queries[i] = int(currentQ)
	}

	var i int = 0
	kruskal(0)
	var optimal = newSpanningTree(n)
	optimal, mst = mst, optimal
	fillSpanningTreeAcc(optimal)

	sort.Ints(queries)
	for _, q := range queries {
		j := i
		for j+1 < len(importantXs) && importantXs[j+1] <= q {
			j++
		}
		if j != i {
			kruskal(importantXs[j])
			optimal, mst = mst, optimal
			fillSpanningTreeAcc(optimal)
			i = j
		}
		ansXor ^= calc(optimal, q)
	}
	printf("%d\n", ansXor)
}

package main

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

var (
	in  = bufio.NewReader(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
)

func flush()                            { out.Flush() }
func scan(a ...interface{})             { fmt.Fscan(in, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(out, f, a...) }

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func unique(a []int) []int {
	j := 1
	for i := 1; i < len(a); i++ {
		if a[i] != a[i-1] {
			a[j] = a[i]
			j++
		}
	}
	return a[:j]
}

// ----------------------------- TEMPLATE END ----------------------------------

type SpanningTree struct {
	id          []int   // edge IDs
	w           []int   // edge weights
	wacc        []int64 // wacc[i] = w[i]+w[i+1]+...
	optimalFrom int
}

type Edge struct {
	id int
	a  int
	b  int
	c  int
	c1 int
}

type DisjointSet struct {
	p []int
}

func (dset *DisjointSet) root(a int) int {
	if dset.p[a] != a {
		dset.p[a] = dset.root(dset.p[a])
	}
	return dset.p[a]
}

func (dset *DisjointSet) join(a, b int) {
	a = dset.root(a)
	b = dset.root(b)
	dset.p[b] = a
}

func (dset *DisjointSet) clear() {
	n := len(dset.p)
	for i := 0; i < n; i++ {
		dset.p[i] = i
	}
}

func newDisjoinSet(n int) *DisjointSet {
	r := &DisjointSet{
		p: make([]int, n),
	}
	for i := 0; i < n; i++ {
		r.p[i] = i
	}
	return r
}

func newSpanningTree(n int) *SpanningTree {
	return &SpanningTree{
		w:           make([]int, n-1),
		id:          make([]int, n-1),
		wacc:        make([]int64, n),
		optimalFrom: 0,
	}
}

func fillSpanningTreeAcc(r *SpanningTree) {
	sort.Slice(r.w, func(i, j int) bool {
		return r.w[i] < r.w[j]
	})
	r.wacc[n-1] = 0
	for i := n - 2; i >= 0; i-- {
		r.wacc[i] = r.wacc[i+1] + int64(r.w[i])
	}
}

const INF = int64(1e12)

var n, nEdges int
var edges []*Edge

var mst *SpanningTree
var dset *DisjointSet

func kruskal(x int) {
	for i := 0; i < nEdges; i++ {
		edges[i].c1 = abs(edges[i].c - x)
	}
	sort.Slice(edges, func(i, j int) bool {
		if edges[i].c1 != edges[j].c1 {
			return edges[i].c1 < edges[j].c1
		}
		return edges[i].id < edges[j].id
	})

	dset.clear()
	mstIndex := 0
	for _, e := range edges {
		if dset.root(e.a) == dset.root(e.b) {
			continue
		}
		mst.id[mstIndex] = e.id
		mst.w[mstIndex] = e.c
		mstIndex++
		dset.join(e.a, e.b)
		if mstIndex == n-1 {
			break
		}
	}
}

func sameSpanningTree(a, b *SpanningTree) bool {
	for i := 0; i < n-1; i++ {
		if a.id[i] != b.id[i] {
			return false
		}
	}
	return true
}

func calc(st *SpanningTree, x int) int64 {
	lo := 0
	hi := n - 1
	mi := 0
	for lo < hi {
		mi = (lo + hi) / 2
		if st.w[mi] <= x {
			lo = mi + 1
		} else {
			hi = mi
		}
	}
	// printf("x=%d, st: %v. lo=%d\n", x, st.w, lo)
	return (st.wacc[lo] - int64(n-1-lo)*int64(x)) + int64(lo)*int64(x) - (st.wacc[0] - st.wacc[lo])
}

func main() {
	defer flush()

	scan(&n, &nEdges)
	edges = make([]*Edge, nEdges)
	mst = newSpanningTree(n)
	dset = newDisjoinSet(n)
	for i := 0; i < nEdges; i++ {
		edges[i] = &Edge{}
		scan(&edges[i].a, &edges[i].b, &edges[i].c)
		edges[i].id = i
		edges[i].a--
		edges[i].b--
	}

	var importantXs []int = []int{0}
	for i := 0; i < nEdges; i++ {
		for j := i + 1; j < nEdges; j++ {
			half := (edges[i].c + edges[j].c) / 2
			importantXs = append(importantXs, half)
			importantXs = append(importantXs, half+1)
			if edges[i].c%2 == edges[j].c%2 {
				importantXs = append(importantXs, half-1)
			}
		}
	}

	sort.Slice(importantXs, func(i, j int) bool {
		return importantXs[i] < importantXs[j]
	})
	importantXs = unique(importantXs)

	// printf("important weights = %v\n", importantXs)

	var explicitQueries, totalQueries int
	var currentQ, queryA, queryB, queryMod int64
	var ansXor int64 = 0
	scan(&explicitQueries, &totalQueries)
	scan(&queryA, &queryB, &queryMod)
	// printf("explicit = %d, total=%d\n", explicitQueries, totalQueries)
	var queries []int = make([]int, totalQueries)
	for i := 0; i < explicitQueries; i++ {
		scan(&currentQ)
		queries[i] = int(currentQ)
	}
	for i := explicitQueries; i < totalQueries; i++ {
		currentQ = (currentQ*queryA + queryB) % queryMod
		queries[i] = int(currentQ)
	}

	var i int = 1
	kruskal(0)
	var optimal = newSpanningTree(n)
	optimal, mst = mst, optimal
	fillSpanningTreeAcc(optimal)

	sort.Ints(queries)
	for _, q := range queries {
		j := i
		for j+1 < len(importantXs) && importantXs[j+1] <= q {
			j++
		}
		if j != i {
			kruskal(importantXs[j])
			if !sameSpanningTree(optimal, mst) {
				optimal, mst = mst, optimal
				fillSpanningTreeAcc(optimal)
			}
			i = j
		}
		ansq := calc(optimal, q)
		// printf("answer(%d) = %d. x=%d\n", q, ansq, importantXs[i])
		ansXor ^= ansq
	}
	printf("%d\n", ansXor)
}

/**
func processQuery(x int64) int64 {
	lo := 0
	hi := len(optimals) - 1
	mi := lo
	for lo < hi {
		mi = (lo + hi) / 2
		if optimals[mi+1].optimalFrom <= x {
			lo = mi + 1
		} else {
			hi = mi
		}
	}

	ans := calc(optimals[lo], x)
	// printf("ans: %d\n", ans)
	return ans
}

*/

package main

import (
	//"bufio"
	"fmt"
	//"os"
	"sort"
	"math/rand"
	"time"
	"bufio"
	"os"
	"strconv"
)

var n, m int

type edge struct {
	from, to int
	w int64
}

var e []*edge

type ByW []*edge

func (a ByW) Len() int           { return len(a) }
func (a ByW) Less(i, j int) bool { return a[i].w < a[j].w }
func (a ByW) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

var r *bufio.Reader

const WRITE = false

func main() {

	f, _ := os.OpenFile("D:\\GO\\src\\codeforces\\edu122\\5\\in.txt", os.O_RDWR, 0)
	defer f.Close()

	if WRITE {

		for i := 0; i < 100; i++ {
			n = 50
			m = 300

			f.WriteString("50 300\n")

			for j := 0; j < m; j++ {
				var from, to, w int
				from = 1 + rand.Intn(n)
				for ;; {
					to = 1 + rand.Intn(n)
					if to != from {
						break
					}
				}
				w = 1 + rand.Intn(1e8)

				f.WriteString(strconv.Itoa(from))
				f.WriteString(" ")
				f.WriteString(strconv.Itoa(to))
				f.WriteString(" ")
				f.WriteString(strconv.Itoa(w))
				f.WriteString("\n")
			}

			//p = 10
			//k = 100
			//a = 1
			//b = 1
			//c = 100

			f.WriteString("1000 100000 192712 386162774 100000000\n")

			for j := 1; j <= 999; j++ {
				x := rand.Intn(1e8)
				f.WriteString(strconv.Itoa(x))
				f.WriteString(" ")
			}
			f.WriteString("100000000")
			f.WriteString("\n")
		}

		return
	}

	rand.Seed(time.Now().UnixNano())
	r = bufio.NewReader(os.Stdin)

	fmt.Fscan(r, &n, &m)

	e = make([]*edge, m)

	for i := 0; i < m; i++ {
		var from, to int
		var w int64
		fmt.Fscan(r, &from)
		fmt.Fscan(r, &to)
		fmt.Fscan(r, &w)

		from--
		to--

		ed := &edge{from, to, w}
		e[i] = ed
	}

	//	st := time.Now().UnixNano()
	ans := solve()
	//	en := time.Now().UnixNano()
	//
	//	fmt.Println((en - st)/1000000)

	fmt.Println(ans)

}

type pair struct {
	v, id int
}

type ByV []*pair

func (a ByV) Len() int           { return len(a) }
func (a ByV) Less(i, j int) bool { return a[i].v < a[j].v }
func (a ByV) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

type item struct {
	la, ra int
	lb, rb int
}

const MAX int = 1e6
var cost []int

const INF = int(1e9) + 5;

type value struct {
	l, r int
	val int64
}

func solve() int64 {
	sort.Sort(ByW(e))

	mp := make(map[int64]int)

	for i := 0; i < len(e); i++ {
		w1 := e[i].w
		for j := i + 1; j < len(e); j++ {
			w2 := e[j].w

			//5 6 7 8 9 10 11 12
			//3 4 5 6 7 8 9 10 11 12

			if w2 > w1 {
				key := (w1 + w2)/2 + 1
				mp[int64(key)] = 0
			}
		}
	}
	for i := 0; i < len(e); i++ {
		w := e[i].w
		mp[int64(w)] = 1
	}

	tree := newInt64InterfaceTreeMap(func(a int64, b int64) bool {
		return a < b
	})

	aa := doCompute(0)
	tree.Set(0, aa)

	for k, _ := range mp {
		ans := doCompute(k)

		tree.Set(k, ans)
	}

	var ans int64

	var p,k,a,b, c int64
	fmt.Fscan(r, &p, &k, &a, &b, &c)

	var x int64

	var i int64
	for i = 0; i < p; i++ {
		fmt.Fscan(r, &x)

		lb := tree.LowerBound(x)

		if lb.Key() == x {
			ans = ans ^ lb.Value().(*value).val
			continue
		}

		lb.Prev()

		k := lb.Key()

		left := lb.Value().(*value).l
		right := lb.Value().(*value).r
		val := lb.Value().(*value).val

		res := val + int64(left) * int64(x - k) - int64(right) * int64(x - k)

		ans = ans ^ res

	}

	for i := p + 1; i <= k; i++ {
		x = (x * a + b) % c

		lb := tree.LowerBound(x)

		if lb.Key() == x {
			ans = ans ^ lb.Value().(*value).val
			continue
		}

		lb.Prev()

		k := lb.Key()

		left := lb.Value().(*value).l
		right := lb.Value().(*value).r
		val := lb.Value().(*value).val

		res := val + int64(left) * int64(x - k) - int64(right) * int64(x - k)

		ans = ans ^ res
	}

	return ans
}

func doCompute(x int64) *value {
	parent := make([]int, n)
	rank := make([]int, n)

	for i := 0; i < n; i++ {
		parent[i] = i
		rank[i] = 0
	}

	idx := sort.Search(m, func(i int) bool {
		ed := e[i]
		return ed.w > x
	})

	var ans *value

	if idx == 0 {
		ans = goFromStart(&parent, &rank, x)

	} else if idx == m {
		ans = goFromEnd(&parent, &rank, x)

	} else {
		ans = goFrom(idx, &parent, &rank, x)
	}

	return ans
}

func find(parent *[]int, p int) int {
	for ; p != (*parent)[p]; {
		(*parent)[p] = (*parent)[(*parent)[p]]
		p = (*parent)[p]
	}

	return p
}

func goFromStart(parent *[]int, rank *[]int, x int64) *value {

	sum := &value{}

	for i := 0; i < m;  i++ {
		ed := e[i]

		a := ed.from
		b := ed.to

		rootA := find(parent, a)
		rootB := find(parent, b)

		if rootA==rootB {
			continue
		}

		sum.val += int64(abs(ed.w - x))
		sum.r++

		if  (*rank)[rootA] < (*rank)[rootB]{
			(*parent)[rootA] = rootB

		} else if (*rank)[rootA] > (*rank)[rootB] {
			(*parent)[rootB] = rootA

		} else {
			(*parent)[rootB] = rootA
			(*rank)[rootA]++
		}
	}

	return sum
}

func goFromEnd(parent *[]int, rank *[]int, x int64) *value {

	sum := &value{}

	for i := m - 1; i >= 0;  i-- {
		ed := e[i]

		a := ed.from
		b := ed.to

		rootA := find(parent, a)
		rootB := find(parent, b)

		if rootA==rootB {
			continue
		}

		sum.val += int64(abs(ed.w - x))
		sum.l++

		if  (*rank)[rootA] < (*rank)[rootB]{
			(*parent)[rootA] = rootB

		} else if (*rank)[rootA] > (*rank)[rootB] {
			(*parent)[rootB] = rootA

		} else {
			(*parent)[rootB] = rootA
			(*rank)[rootA]++
		}
	}

	return sum
}

func goFrom(idx int, parent *[]int, rank *[]int, x int64) *value {
	sum := &value{}

	var i, j int

	i = idx
	j = idx - 1

	for ; j >= 0 && i < m; {
		e1 := e[i]
		e2 := e[j]

		if abs(e1.w - x) <= abs(e2.w - x) {
			//e1
			a := e1.from
			b := e1.to

			rootA := find(parent, a)
			rootB := find(parent, b)

			if rootA==rootB {
				i++
				continue
			}

			sum.r++
			sum.val += int64(abs(e1.w - x))

			if  (*rank)[rootA] < (*rank)[rootB]{
				(*parent)[rootA] = rootB

			} else if (*rank)[rootA] > (*rank)[rootB] {
				(*parent)[rootB] = rootA

			} else {
				(*parent)[rootB] = rootA
				(*rank)[rootA]++
			}

			i++
		} else {
			//e2
			a := e2.from
			b := e2.to

			rootA := find(parent, a)
			rootB := find(parent, b)

			if rootA==rootB {
				j--
				continue
			}

			sum.l++
			sum.val += int64(abs(e2.w - x))

			if  (*rank)[rootA] < (*rank)[rootB]{
				(*parent)[rootA] = rootB

			} else if (*rank)[rootA] > (*rank)[rootB] {
				(*parent)[rootB] = rootA

			} else {
				(*parent)[rootB] = rootA
				(*rank)[rootA]++
			}

			j--
		}
	}

	if j > 0 {

		for k := j; k >= 0; k-- {
			ed := e[k]

			a := ed.from
			b := ed.to

			rootA := find(parent, a)
			rootB := find(parent, b)

			if rootA==rootB {
				continue
			}

			sum.val += int64(abs(ed.w - x))
			sum.l++

			if  (*rank)[rootA] < (*rank)[rootB]{
				(*parent)[rootA] = rootB

			} else if (*rank)[rootA] > (*rank)[rootB] {
				(*parent)[rootB] = rootA

			} else {
				(*parent)[rootB] = rootA
				(*rank)[rootA]++
			}

		}

	} else if i < m - 1 {

		for k := i; k < m; k++ {
			ed := e[k]

			a := ed.from
			b := ed.to

			rootA := find(parent, a)
			rootB := find(parent, b)

			if rootA==rootB {
				continue
			}

			sum.val += int64(abs(ed.w - x))
			sum.r++

			if  (*rank)[rootA] < (*rank)[rootB]{
				(*parent)[rootA] = rootB

			} else if (*rank)[rootA] > (*rank)[rootB] {
				(*parent)[rootB] = rootA

			} else {
				(*parent)[rootB] = rootA
				(*rank)[rootA]++
			}
		}
	}

	return sum
}

func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

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

func add(idx int, delta int, bit *[]int, n int) {
	for ; idx <= n; idx += idx & -idx {
		(*bit)[idx] += delta
	}
}

func get(idx int, bit *[]int) int {
	ret := 0
	for ; idx > 0; idx -= idx & -idx {
		ret += (*bit)[idx];
	}
	return ret
}

//A -  1 3 5 3 1

//B -  4 3 6 1

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

type int64InterfaceTreeMap struct {
	endNode   *nodeInt64InterfaceTreeMap
	beginNode *nodeInt64InterfaceTreeMap
	count     int
	// Less returns a < b
	Less func(a int64, b int64) bool
}

type nodeInt64InterfaceTreeMap struct {
	right   *nodeInt64InterfaceTreeMap
	left    *nodeInt64InterfaceTreeMap
	parent  *nodeInt64InterfaceTreeMap
	isBlack bool
	key     int64
	value   interface{}
}

// New creates and returns new TreeMap.
// Parameter less is a function returning a < b.
func newInt64InterfaceTreeMap(less func(a int64, b int64) bool) *int64InterfaceTreeMap {
	endNode := &nodeInt64InterfaceTreeMap{isBlack: true}
	return &int64InterfaceTreeMap{beginNode: endNode, endNode: endNode, Less: less}
}

// Len returns total count of elements in a map.
// Complexity: O(1).
func (t *int64InterfaceTreeMap) Len() int { return t.count }

// Set sets the value and silently overrides previous value if it exists.
// Complexity: O(log N).
func (t *int64InterfaceTreeMap) Set(key int64, value interface{}) {
	parent := t.endNode
	current := parent.left
	less := true
	for current != nil {
		parent = current
		switch {
		case t.Less(key, current.key):
			current = current.left
			less = true
		case t.Less(current.key, key):
			current = current.right
			less = false
		default:
			current.value = value
			return
		}
	}
	x := &nodeInt64InterfaceTreeMap{parent: parent, value: value, key: key}
	if less {
		parent.left = x
	} else {
		parent.right = x
	}
	if t.beginNode.left != nil {
		t.beginNode = t.beginNode.left
	}
	t.insertFixup(x)
	t.count++
}

// Del deletes the value.
// Complexity: O(log N).
func (t *int64InterfaceTreeMap) Del(key int64) {
	z := t.findNode(key)
	if z == nil {
		return
	}
	if t.beginNode == z {
		if z.right != nil {
			t.beginNode = z.right
		} else {
			t.beginNode = z.parent
		}
	}
	t.count--
	removeNodeInt64InterfaceTreeMap(t.endNode.left, z)
}

// Clear clears the map.
// Complexity: O(1).
func (t *int64InterfaceTreeMap) Clear() {
	t.count = 0
	t.beginNode = t.endNode
	t.endNode.left = nil
}

// Get retrieves a value from a map for specified key and reports if it exists.
// Complexity: O(log N).
func (t *int64InterfaceTreeMap) Get(id int64) (interface{}, bool) {
	node := t.findNode(id)
	if node == nil {
		node = t.endNode
	}
	return node.value, node != t.endNode
}

// Contains checks if key exists in a map.
// Complexity: O(log N)
func (t *int64InterfaceTreeMap) Contains(id int64) bool { return t.findNode(id) != nil }

// Range returns a pair of iterators that you can use to go through all the keys in the range [from, to].
// More specifically it returns iterators pointing to lower bound and upper bound.
// Complexity: O(log N).
func (t *int64InterfaceTreeMap) Range(from, to int64) (forwardIteratorInt64InterfaceTreeMap, forwardIteratorInt64InterfaceTreeMap) {
	return t.LowerBound(from), t.UpperBound(to)
}

// LowerBound returns an iterator pointing to the first element that is not less than the given key.
// Complexity: O(log N).
func (t *int64InterfaceTreeMap) LowerBound(key int64) forwardIteratorInt64InterfaceTreeMap {
	result := t.endNode
	node := t.endNode.left
	if node == nil {
		return forwardIteratorInt64InterfaceTreeMap{tree: t, node: t.endNode}
	}
	for {
		if t.Less(node.key, key) {
			if node.right != nil {
				node = node.right
			} else {
				return forwardIteratorInt64InterfaceTreeMap{tree: t, node: result}
			}
		} else {
			result = node
			if node.left != nil {
				node = node.left
			} else {
				return forwardIteratorInt64InterfaceTreeMap{tree: t, node: result}
			}
		}
	}
}

// UpperBound returns an iterator pointing to the first element that is greater than the given key.
// Complexity: O(log N).
func (t *int64InterfaceTreeMap) UpperBound(key int64) forwardIteratorInt64InterfaceTreeMap {
	result := t.endNode
	node := t.endNode.left
	if node == nil {
		return forwardIteratorInt64InterfaceTreeMap{tree: t, node: t.endNode}
	}
	for {
		if !t.Less(key, node.key) {
			if node.right != nil {
				node = node.right
			} else {
				return forwardIteratorInt64InterfaceTreeMap{tree: t, node: result}
			}
		} else {
			result = node
			if node.left != nil {
				node = node.left
			} else {
				return forwardIteratorInt64InterfaceTreeMap{tree: t, node: result}
			}
		}
	}
}

// Iterator returns an iterator for tree map.
// It starts at the first element and goes to the one-past-the-end position.
// You can iterate a map at O(N) complexity.
// Method complexity: O(1)
func (t *int64InterfaceTreeMap) Iterator() forwardIteratorInt64InterfaceTreeMap {
	return forwardIteratorInt64InterfaceTreeMap{tree: t, node: t.beginNode}
}

// Reverse returns a reverse iterator for tree map.
// It starts at the last element and goes to the one-before-the-start position.
// You can iterate a map at O(N) complexity.
// Method complexity: O(log N)
func (t *int64InterfaceTreeMap) Reverse() reverseIteratorInt64InterfaceTreeMap {
	node := t.endNode.left
	if node != nil {
		node = mostRightInt64InterfaceTreeMap(node)
	}
	return reverseIteratorInt64InterfaceTreeMap{tree: t, node: node}
}

func (t *int64InterfaceTreeMap) findNode(id int64) *nodeInt64InterfaceTreeMap {
	current := t.endNode.left
	for current != nil {
		switch {
		case t.Less(id, current.key):
			current = current.left
		case t.Less(current.key, id):
			current = current.right
		default:
			return current
		}
	}
	return nil
}

func mostLeftInt64InterfaceTreeMap(x *nodeInt64InterfaceTreeMap) *nodeInt64InterfaceTreeMap {
	for x.left != nil {
		x = x.left
	}
	return x
}

func mostRightInt64InterfaceTreeMap(x *nodeInt64InterfaceTreeMap) *nodeInt64InterfaceTreeMap {
	for x.right != nil {
		x = x.right
	}
	return x
}

func successorInt64InterfaceTreeMap(x *nodeInt64InterfaceTreeMap) *nodeInt64InterfaceTreeMap {
	if x.right != nil {
		return mostLeftInt64InterfaceTreeMap(x.right)
	}
	for x != x.parent.left {
		x = x.parent
	}
	return x.parent
}

func predecessorInt64InterfaceTreeMap(x *nodeInt64InterfaceTreeMap) *nodeInt64InterfaceTreeMap {
	if x.left != nil {
		return mostRightInt64InterfaceTreeMap(x.left)
	}
	for x.parent != nil && x != x.parent.right {
		x = x.parent
	}
	return x.parent
}

func rotateLeftInt64InterfaceTreeMap(x *nodeInt64InterfaceTreeMap) {
	y := x.right
	x.right = y.left
	if x.right != nil {
		x.right.parent = x
	}
	y.parent = x.parent
	if x == x.parent.left {
		x.parent.left = y
	} else {
		x.parent.right = y
	}
	y.left = x
	x.parent = y
}

func rotateRightInt64InterfaceTreeMap(x *nodeInt64InterfaceTreeMap) {
	y := x.left
	x.left = y.right
	if x.left != nil {
		x.left.parent = x
	}
	y.parent = x.parent
	if x == x.parent.left {
		x.parent.left = y
	} else {
		x.parent.right = y
	}
	y.right = x
	x.parent = y
}

func (t *int64InterfaceTreeMap) insertFixup(x *nodeInt64InterfaceTreeMap) {
	root := t.endNode.left
	x.isBlack = x == root
	for x != root && !x.parent.isBlack {
		if x.parent == x.parent.parent.left {
			y := x.parent.parent.right
			if y != nil && !y.isBlack {
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = x == root
				y.isBlack = true
			} else {
				if x != x.parent.left {
					x = x.parent
					rotateLeftInt64InterfaceTreeMap(x)
				}
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = false
				rotateRightInt64InterfaceTreeMap(x)
				break
			}
		} else {
			y := x.parent.parent.left
			if y != nil && !y.isBlack {
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = x == root
				y.isBlack = true
			} else {
				if x == x.parent.left {
					x = x.parent
					rotateRightInt64InterfaceTreeMap(x)
				}
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = false
				rotateLeftInt64InterfaceTreeMap(x)
				break
			}
		}
	}
}

// nolint: gocyclo
//noinspection GoNilness
func removeNodeInt64InterfaceTreeMap(root *nodeInt64InterfaceTreeMap, z *nodeInt64InterfaceTreeMap) {
	var y *nodeInt64InterfaceTreeMap
	if z.left == nil || z.right == nil {
		y = z
	} else {
		y = successorInt64InterfaceTreeMap(z)
	}
	var x *nodeInt64InterfaceTreeMap
	if y.left != nil {
		x = y.left
	} else {
		x = y.right
	}
	var w *nodeInt64InterfaceTreeMap
	if x != nil {
		x.parent = y.parent
	}
	if y == y.parent.left {
		y.parent.left = x
		if y != root {
			w = y.parent.right
		} else {
			root = x // w == nil
		}
	} else {
		y.parent.right = x
		w = y.parent.left
	}
	removedBlack := y.isBlack
	if y != z {
		y.parent = z.parent
		if z == z.parent.left {
			y.parent.left = y
		} else {
			y.parent.right = y
		}
		y.left = z.left
		y.left.parent = y
		y.right = z.right
		if y.right != nil {
			y.right.parent = y
		}
		y.isBlack = z.isBlack
		if root == z {
			root = y
		}
	}
	if removedBlack && root != nil {
		if x != nil {
			x.isBlack = true
		} else {
			for {
				if w != w.parent.left {
					if !w.isBlack {
						w.isBlack = true
						w.parent.isBlack = false
						rotateLeftInt64InterfaceTreeMap(w.parent)
						if root == w.left {
							root = w
						}
						w = w.left.right
					}
					if (w.left == nil || w.left.isBlack) && (w.right == nil || w.right.isBlack) {
						w.isBlack = false
						x = w.parent
						if x == root || !x.isBlack {
							x.isBlack = true
							break
						}
						if x == x.parent.left {
							w = x.parent.right
						} else {
							w = x.parent.left
						}
					} else {
						if w.right == nil || w.right.isBlack {
							w.left.isBlack = true
							w.isBlack = false
							rotateRightInt64InterfaceTreeMap(w)
							w = w.parent
						}
						w.isBlack = w.parent.isBlack
						w.parent.isBlack = true
						w.right.isBlack = true
						rotateLeftInt64InterfaceTreeMap(w.parent)
						break
					}
				} else {
					if !w.isBlack {
						w.isBlack = true
						w.parent.isBlack = false
						rotateRightInt64InterfaceTreeMap(w.parent)
						if root == w.right {
							root = w
						}
						w = w.right.left
					}
					if (w.left == nil || w.left.isBlack) && (w.right == nil || w.right.isBlack) {
						w.isBlack = false
						x = w.parent
						if !x.isBlack || x == root {
							x.isBlack = true
							break
						}
						if x == x.parent.left {
							w = x.parent.right
						} else {
							w = x.parent.left
						}
					} else {
						if w.left == nil || w.left.isBlack {
							w.right.isBlack = true
							w.isBlack = false
							rotateLeftInt64InterfaceTreeMap(w)
							w = w.parent
						}
						w.isBlack = w.parent.isBlack
						w.parent.isBlack = true
						w.left.isBlack = true
						rotateRightInt64InterfaceTreeMap(w.parent)
						break
					}
				}
			}
		}
	}
}

// ForwardIterator represents a position in a tree map.
// It is designed to iterate a map in a forward order.
// It can point to any position from the first element to the one-past-the-end element.
type forwardIteratorInt64InterfaceTreeMap struct {
	tree *int64InterfaceTreeMap
	node *nodeInt64InterfaceTreeMap
}

// Valid reports if an iterator's position is valid.
// In other words it returns true if an iterator is not at the one-past-the-end position.
func (i forwardIteratorInt64InterfaceTreeMap) Valid() bool { return i.node != i.tree.endNode }

// Next moves an iterator to the next element.
// It panics if goes out of bounds.
func (i *forwardIteratorInt64InterfaceTreeMap) Next() {
	if i.node == i.tree.endNode {
		panic("out of bound iteration")
	}
	i.node = successorInt64InterfaceTreeMap(i.node)
}

// Prev moves an iterator to the previous element.
// It panics if goes out of bounds.
func (i *forwardIteratorInt64InterfaceTreeMap) Prev() {
	i.node = predecessorInt64InterfaceTreeMap(i.node)
	if i.node == nil {
		panic("out of bound iteration")
	}
}

// Key returns a key at an iterator's position
func (i forwardIteratorInt64InterfaceTreeMap) Key() int64 { return i.node.key }

// Value returns a value at an iterator's position
func (i forwardIteratorInt64InterfaceTreeMap) Value() interface{} { return i.node.value }

// ReverseIterator represents a position in a tree map.
// It is designed to iterate a map in a reverse order.
// It can point to any position from the one-before-the-start element to the last element.
type reverseIteratorInt64InterfaceTreeMap struct {
	tree *int64InterfaceTreeMap
	node *nodeInt64InterfaceTreeMap
}

// Valid reports if an iterator's position is valid.
// In other words it returns true if an iterator is not at the one-before-the-start position.
func (i reverseIteratorInt64InterfaceTreeMap) Valid() bool { return i.node != nil }

// Next moves an iterator to the next element in reverse order.
// It panics if goes out of bounds.
func (i *reverseIteratorInt64InterfaceTreeMap) Next() {
	if i.node == nil {
		panic("out of bound iteration")
	}
	i.node = predecessorInt64InterfaceTreeMap(i.node)
}

// Prev moves an iterator to the previous element in reverse order.
// It panics if goes out of bounds.
func (i *reverseIteratorInt64InterfaceTreeMap) Prev() {
	if i.node != nil {
		i.node = successorInt64InterfaceTreeMap(i.node)
	} else {
		i.node = i.tree.beginNode
	}
	if i.node == i.tree.endNode {
		panic("out of bound iteration")
	}
}

// Key returns a key at an iterator's position
func (i reverseIteratorInt64InterfaceTreeMap) Key() int64 { return i.node.key }

// Value returns a value at an iterator's position
func (i reverseIteratorInt64InterfaceTreeMap) Value() interface{} { return i.node.value }

package main

import (
	//"bufio"
	"fmt"
	//"os"
	"sort"
	"math/rand"
	"time"
	"bufio"
	"os"
	"strconv"
)

var n, m int

type edge struct {
	from, to int
	w int
}

var e []*edge

type ByW []*edge

func (a ByW) Len() int           { return len(a) }
func (a ByW) Less(i, j int) bool { return a[i].w < a[j].w }
func (a ByW) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

var r *bufio.Reader

const WRITE = false

func main() {

	f, _ := os.OpenFile("D:\\GO\\src\\codeforces\\edu122\\5\\in.txt", os.O_RDWR, 0)
	defer f.Close()

	if WRITE {

		for i := 0; i < 100; i++ {
			n = 50
			m = 300

			f.WriteString("50 300\n")

			for j := 0; j < m; j++ {
				var from, to, w int
				from = 1 + rand.Intn(n)
				for ;; {
					to = 1 + rand.Intn(n)
					if to != from {
						break
					}
				}
				w = 1 + rand.Intn(1e8)

				f.WriteString(strconv.Itoa(from))
				f.WriteString(" ")
				f.WriteString(strconv.Itoa(to))
				f.WriteString(" ")
				f.WriteString(strconv.Itoa(w))
				f.WriteString("\n")
			}

			//p = 10
			//k = 100
			//a = 1
			//b = 1
			//c = 100

			f.WriteString("1000 100000 192712 386162774 100000000\n")

			for j := 1; j <= 999; j++ {
				x := rand.Intn(1e8)
				f.WriteString(strconv.Itoa(x))
				f.WriteString(" ")
			}
			f.WriteString("100000000")
			f.WriteString("\n")
		}

		return
	}

	rand.Seed(time.Now().UnixNano())
	r = bufio.NewReader(os.Stdin)

	fmt.Fscan(r, &n, &m)

	e = make([]*edge, m)

	for i := 0; i < m; i++ {
		var from, to, w int
		fmt.Fscan(r, &from)
		fmt.Fscan(r, &to)
		fmt.Fscan(r, &w)

		from--
		to--

		ed := &edge{from, to, w}
		e[i] = ed
	}

	//	st := time.Now().UnixNano()
	ans := solve()
	//	en := time.Now().UnixNano()
	//
	//	fmt.Println((en - st)/1000000)

	fmt.Println(ans)

}

type pair struct {
	v, id int
}

type ByV []*pair

func (a ByV) Len() int           { return len(a) }
func (a ByV) Less(i, j int) bool { return a[i].v < a[j].v }
func (a ByV) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

type item struct {
	la, ra int
	lb, rb int
}

const MAX int = 1e6
var cost []int

const INF = int(1e9) + 5;

type value struct {
	l, r int
	val int64
}

func solve() int64 {
	sort.Sort(ByW(e))

	mp := make(map[int]int)

	for i := 0; i < len(e); i++ {
		w1 := e[i].w
		for j := i + 1; j < len(e); j++ {
			w2 := e[j].w

			//5 6 7 8 9 10 11 12
			//3 4 5 6 7 8 9 10 11 12

			if w2 > w1 {
				key := (w1 + w2)/2 + 1
				mp[key] = 0
			}
		}
	}
	for i := 0; i < len(e); i++ {
		w := e[i].w
		mp[w] = 1
	}

	tree := newIntInterfaceTreeMap(func(a int, b int) bool {
		return a < b
	})

	aa := doCompute(0)
	tree.Set(0, aa)

	for k, _ := range mp {
		ans := doCompute(k)

		tree.Set(k, ans)
	}

	var ans int64

	var p,k,a,b, c int
	fmt.Fscan(r, &p, &k, &a, &b, &c)

	var x int

	for i := 0; i < p; i++ {
		fmt.Fscan(r, &x)

		v, r := tree.Get(x)

		if r {
			ans = ans ^ v.(*value).val
			continue
		}

		lb := tree.UpperBound(x)
		lb.Prev()
		if lb.node == nil {
			continue
		}

		k := lb.Key()

		left := lb.Value().(*value).l
		right := lb.Value().(*value).r
		val := lb.Value().(*value).val

		res := val + int64(left) * int64(x - k) - int64(right) * int64(x - k)

		ans = ans ^ res

	}

	for i := p + 1; i <= k; i++ {
		x = (x * a + b) % c

		v, r := tree.Get(x)

		if r {
			ans = ans ^ v.(*value).val
			continue
		}

		lb := tree.UpperBound(x)
		lb.Prev()
		if lb.node == nil {
			continue
		}

		k := lb.Key()

		left := lb.Value().(*value).l
		right := lb.Value().(*value).r
		val := lb.Value().(*value).val

		res := val + int64(left) * int64(x - k) - int64(right) * int64(x - k)

		ans = ans ^ res
	}

	return ans
}

func doCompute(x int) *value {
	parent := make([]int, n)
	rank := make([]int, n)

	for i := 0; i < n; i++ {
		parent[i] = i
		rank[i] = 0
	}

	idx := sort.Search(m, func(i int) bool {
		ed := e[i]
		return ed.w > x
	})

	var ans *value

	if idx == 0 {
		ans = goFromStart(&parent, &rank, x)

	} else if idx == m {
		ans = goFromEnd(&parent, &rank, x)

	} else {
		ans = goFrom(idx, &parent, &rank, x)
	}

	return ans
}

func find(parent *[]int, p int) int {
	for ; p != (*parent)[p]; {
		(*parent)[p] = (*parent)[(*parent)[p]]
		p = (*parent)[p]
	}

	return p
}

func goFromStart(parent *[]int, rank *[]int, x int) *value {

	sum := &value{}

	for i := 0; i < m;  i++ {
		ed := e[i]

		a := ed.from
		b := ed.to

		rootA := find(parent, a)
		rootB := find(parent, b)

		if rootA==rootB {
			continue
		}

		sum.val += int64(abs(ed.w - x))
		sum.r++

		if  (*rank)[rootA] < (*rank)[rootB]{
			(*parent)[rootA] = rootB

		} else if (*rank)[rootA] > (*rank)[rootB] {
			(*parent)[rootB] = rootA

		} else {
			(*parent)[rootB] = rootA
			(*rank)[rootA]++
		}
	}

	return sum
}

func goFromEnd(parent *[]int, rank *[]int, x int) *value {

	sum := &value{}

	for i := m - 1; i >= 0;  i-- {
		ed := e[i]

		a := ed.from
		b := ed.to

		rootA := find(parent, a)
		rootB := find(parent, b)

		if rootA==rootB {
			continue
		}

		sum.val += int64(abs(ed.w - x))
		sum.l++

		if  (*rank)[rootA] < (*rank)[rootB]{
			(*parent)[rootA] = rootB

		} else if (*rank)[rootA] > (*rank)[rootB] {
			(*parent)[rootB] = rootA

		} else {
			(*parent)[rootB] = rootA
			(*rank)[rootA]++
		}
	}

	return sum
}

func goFrom(idx int, parent *[]int, rank *[]int, x int) *value {
	sum := &value{}

	var i, j int

	i = idx
	j = idx - 1

	for ; j >= 0 && i < m; {
		e1 := e[i]
		e2 := e[j]

		if abs(e1.w - x) <= abs(e2.w - x) {
			//e1
			a := e1.from
			b := e1.to

			rootA := find(parent, a)
			rootB := find(parent, b)

			if rootA==rootB {
				i++
				continue
			}

			sum.r++
			sum.val += int64(abs(e1.w - x))

			if  (*rank)[rootA] < (*rank)[rootB]{
				(*parent)[rootA] = rootB

			} else if (*rank)[rootA] > (*rank)[rootB] {
				(*parent)[rootB] = rootA

			} else {
				(*parent)[rootB] = rootA
				(*rank)[rootA]++
			}

			i++
		} else {
			//e2
			a := e2.from
			b := e2.to

			rootA := find(parent, a)
			rootB := find(parent, b)

			if rootA==rootB {
				j--
				continue
			}

			sum.l++
			sum.val += int64(abs(e2.w - x))

			if  (*rank)[rootA] < (*rank)[rootB]{
				(*parent)[rootA] = rootB

			} else if (*rank)[rootA] > (*rank)[rootB] {
				(*parent)[rootB] = rootA

			} else {
				(*parent)[rootB] = rootA
				(*rank)[rootA]++
			}

			j--
		}
	}

	if j > 0 {

		for k := j; k >= 0; k-- {
			ed := e[k]

			a := ed.from
			b := ed.to

			rootA := find(parent, a)
			rootB := find(parent, b)

			if rootA==rootB {
				continue
			}

			sum.val += int64(abs(ed.w - x))
			sum.l++

			if  (*rank)[rootA] < (*rank)[rootB]{
				(*parent)[rootA] = rootB

			} else if (*rank)[rootA] > (*rank)[rootB] {
				(*parent)[rootB] = rootA

			} else {
				(*parent)[rootB] = rootA
				(*rank)[rootA]++
			}

		}

	} else if i < m - 1 {

		for k := i; k < m; k++ {
			ed := e[k]

			a := ed.from
			b := ed.to

			rootA := find(parent, a)
			rootB := find(parent, b)

			if rootA==rootB {
				continue
			}

			sum.val += int64(abs(ed.w - x))
			sum.r++

			if  (*rank)[rootA] < (*rank)[rootB]{
				(*parent)[rootA] = rootB

			} else if (*rank)[rootA] > (*rank)[rootB] {
				(*parent)[rootB] = rootA

			} else {
				(*parent)[rootB] = rootA
				(*rank)[rootA]++
			}
		}
	}

	return sum
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

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

func add(idx int, delta int, bit *[]int, n int) {
	for ; idx <= n; idx += idx & -idx {
		(*bit)[idx] += delta
	}
}

func get(idx int, bit *[]int) int {
	ret := 0
	for ; idx > 0; idx -= idx & -idx {
		ret += (*bit)[idx];
	}
	return ret
}

//A -  1 3 5 3 1

//B -  4 3 6 1

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

type intInterfaceTreeMap struct {
	endNode   *nodeIntInterfaceTreeMap
	beginNode *nodeIntInterfaceTreeMap
	count     int
	// Less returns a < b
	Less func(a int, b int) bool
}

type nodeIntInterfaceTreeMap struct {
	right   *nodeIntInterfaceTreeMap
	left    *nodeIntInterfaceTreeMap
	parent  *nodeIntInterfaceTreeMap
	isBlack bool
	key     int
	value   interface{}
}

// New creates and returns new TreeMap.
// Parameter less is a function returning a < b.
func newIntInterfaceTreeMap(less func(a int, b int) bool) *intInterfaceTreeMap {
	endNode := &nodeIntInterfaceTreeMap{isBlack: true}
	return &intInterfaceTreeMap{beginNode: endNode, endNode: endNode, Less: less}
}

// Len returns total count of elements in a map.
// Complexity: O(1).
func (t *intInterfaceTreeMap) Len() int { return t.count }

// Set sets the value and silently overrides previous value if it exists.
// Complexity: O(log N).
func (t *intInterfaceTreeMap) Set(key int, value interface{}) {
	parent := t.endNode
	current := parent.left
	less := true
	for current != nil {
		parent = current
		switch {
		case t.Less(key, current.key):
			current = current.left
			less = true
		case t.Less(current.key, key):
			current = current.right
			less = false
		default:
			current.value = value
			return
		}
	}
	x := &nodeIntInterfaceTreeMap{parent: parent, value: value, key: key}
	if less {
		parent.left = x
	} else {
		parent.right = x
	}
	if t.beginNode.left != nil {
		t.beginNode = t.beginNode.left
	}
	t.insertFixup(x)
	t.count++
}

// Del deletes the value.
// Complexity: O(log N).
func (t *intInterfaceTreeMap) Del(key int) {
	z := t.findNode(key)
	if z == nil {
		return
	}
	if t.beginNode == z {
		if z.right != nil {
			t.beginNode = z.right
		} else {
			t.beginNode = z.parent
		}
	}
	t.count--
	removeNodeIntInterfaceTreeMap(t.endNode.left, z)
}

// Clear clears the map.
// Complexity: O(1).
func (t *intInterfaceTreeMap) Clear() {
	t.count = 0
	t.beginNode = t.endNode
	t.endNode.left = nil
}

// Get retrieves a value from a map for specified key and reports if it exists.
// Complexity: O(log N).
func (t *intInterfaceTreeMap) Get(id int) (interface{}, bool) {
	node := t.findNode(id)
	if node == nil {
		node = t.endNode
	}
	return node.value, node != t.endNode
}

// Contains checks if key exists in a map.
// Complexity: O(log N)
func (t *intInterfaceTreeMap) Contains(id int) bool { return t.findNode(id) != nil }

// Range returns a pair of iterators that you can use to go through all the keys in the range [from, to].
// More specifically it returns iterators pointing to lower bound and upper bound.
// Complexity: O(log N).
func (t *intInterfaceTreeMap) Range(from, to int) (forwardIteratorIntInterfaceTreeMap, forwardIteratorIntInterfaceTreeMap) {
	return t.LowerBound(from), t.UpperBound(to)
}

// LowerBound returns an iterator pointing to the first element that is not less than the given key.
// Complexity: O(log N).
func (t *intInterfaceTreeMap) LowerBound(key int) forwardIteratorIntInterfaceTreeMap {
	result := t.endNode
	node := t.endNode.left
	if node == nil {
		return forwardIteratorIntInterfaceTreeMap{tree: t, node: t.endNode}
	}
	for {
		if t.Less(node.key, key) {
			if node.right != nil {
				node = node.right
			} else {
				return forwardIteratorIntInterfaceTreeMap{tree: t, node: result}
			}
		} else {
			result = node
			if node.left != nil {
				node = node.left
			} else {
				return forwardIteratorIntInterfaceTreeMap{tree: t, node: result}
			}
		}
	}
}

// UpperBound returns an iterator pointing to the first element that is greater than the given key.
// Complexity: O(log N).
func (t *intInterfaceTreeMap) UpperBound(key int) forwardIteratorIntInterfaceTreeMap {
	result := t.endNode
	node := t.endNode.left
	if node == nil {
		return forwardIteratorIntInterfaceTreeMap{tree: t, node: t.endNode}
	}
	for {
		if !t.Less(key, node.key) {
			if node.right != nil {
				node = node.right
			} else {
				return forwardIteratorIntInterfaceTreeMap{tree: t, node: result}
			}
		} else {
			result = node
			if node.left != nil {
				node = node.left
			} else {
				return forwardIteratorIntInterfaceTreeMap{tree: t, node: result}
			}
		}
	}
}

// Iterator returns an iterator for tree map.
// It starts at the first element and goes to the one-past-the-end position.
// You can iterate a map at O(N) complexity.
// Method complexity: O(1)
func (t *intInterfaceTreeMap) Iterator() forwardIteratorIntInterfaceTreeMap {
	return forwardIteratorIntInterfaceTreeMap{tree: t, node: t.beginNode}
}

// Reverse returns a reverse iterator for tree map.
// It starts at the last element and goes to the one-before-the-start position.
// You can iterate a map at O(N) complexity.
// Method complexity: O(log N)
func (t *intInterfaceTreeMap) Reverse() reverseIteratorIntInterfaceTreeMap {
	node := t.endNode.left
	if node != nil {
		node = mostRightIntInterfaceTreeMap(node)
	}
	return reverseIteratorIntInterfaceTreeMap{tree: t, node: node}
}

func (t *intInterfaceTreeMap) findNode(id int) *nodeIntInterfaceTreeMap {
	current := t.endNode.left
	for current != nil {
		switch {
		case t.Less(id, current.key):
			current = current.left
		case t.Less(current.key, id):
			current = current.right
		default:
			return current
		}
	}
	return nil
}

func mostLeftIntInterfaceTreeMap(x *nodeIntInterfaceTreeMap) *nodeIntInterfaceTreeMap {
	for x.left != nil {
		x = x.left
	}
	return x
}

func mostRightIntInterfaceTreeMap(x *nodeIntInterfaceTreeMap) *nodeIntInterfaceTreeMap {
	for x.right != nil {
		x = x.right
	}
	return x
}

func successorIntInterfaceTreeMap(x *nodeIntInterfaceTreeMap) *nodeIntInterfaceTreeMap {
	if x.right != nil {
		return mostLeftIntInterfaceTreeMap(x.right)
	}
	for x != x.parent.left {
		x = x.parent
	}
	return x.parent
}

func predecessorIntInterfaceTreeMap(x *nodeIntInterfaceTreeMap) *nodeIntInterfaceTreeMap {
	if x.left != nil {
		return mostRightIntInterfaceTreeMap(x.left)
	}
	for x.parent != nil && x != x.parent.right {
		x = x.parent
	}
	return x.parent
}

func rotateLeftIntInterfaceTreeMap(x *nodeIntInterfaceTreeMap) {
	y := x.right
	x.right = y.left
	if x.right != nil {
		x.right.parent = x
	}
	y.parent = x.parent
	if x == x.parent.left {
		x.parent.left = y
	} else {
		x.parent.right = y
	}
	y.left = x
	x.parent = y
}

func rotateRightIntInterfaceTreeMap(x *nodeIntInterfaceTreeMap) {
	y := x.left
	x.left = y.right
	if x.left != nil {
		x.left.parent = x
	}
	y.parent = x.parent
	if x == x.parent.left {
		x.parent.left = y
	} else {
		x.parent.right = y
	}
	y.right = x
	x.parent = y
}

func (t *intInterfaceTreeMap) insertFixup(x *nodeIntInterfaceTreeMap) {
	root := t.endNode.left
	x.isBlack = x == root
	for x != root && !x.parent.isBlack {
		if x.parent == x.parent.parent.left {
			y := x.parent.parent.right
			if y != nil && !y.isBlack {
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = x == root
				y.isBlack = true
			} else {
				if x != x.parent.left {
					x = x.parent
					rotateLeftIntInterfaceTreeMap(x)
				}
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = false
				rotateRightIntInterfaceTreeMap(x)
				break
			}
		} else {
			y := x.parent.parent.left
			if y != nil && !y.isBlack {
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = x == root
				y.isBlack = true
			} else {
				if x == x.parent.left {
					x = x.parent
					rotateRightIntInterfaceTreeMap(x)
				}
				x = x.parent
				x.isBlack = true
				x = x.parent
				x.isBlack = false
				rotateLeftIntInterfaceTreeMap(x)
				break
			}
		}
	}
}

// nolint: gocyclo
//noinspection GoNilness
func removeNodeIntInterfaceTreeMap(root *nodeIntInterfaceTreeMap, z *nodeIntInterfaceTreeMap) {
	var y *nodeIntInterfaceTreeMap
	if z.left == nil || z.right == nil {
		y = z
	} else {
		y = successorIntInterfaceTreeMap(z)
	}
	var x *nodeIntInterfaceTreeMap
	if y.left != nil {
		x = y.left
	} else {
		x = y.right
	}
	var w *nodeIntInterfaceTreeMap
	if x != nil {
		x.parent = y.parent
	}
	if y == y.parent.left {
		y.parent.left = x
		if y != root {
			w = y.parent.right
		} else {
			root = x // w == nil
		}
	} else {
		y.parent.right = x
		w = y.parent.left
	}
	removedBlack := y.isBlack
	if y != z {
		y.parent = z.parent
		if z == z.parent.left {
			y.parent.left = y
		} else {
			y.parent.right = y
		}
		y.left = z.left
		y.left.parent = y
		y.right = z.right
		if y.right != nil {
			y.right.parent = y
		}
		y.isBlack = z.isBlack
		if root == z {
			root = y
		}
	}
	if removedBlack && root != nil {
		if x != nil {
			x.isBlack = true
		} else {
			for {
				if w != w.parent.left {
					if !w.isBlack {
						w.isBlack = true
						w.parent.isBlack = false
						rotateLeftIntInterfaceTreeMap(w.parent)
						if root == w.left {
							root = w
						}
						w = w.left.right
					}
					if (w.left == nil || w.left.isBlack) && (w.right == nil || w.right.isBlack) {
						w.isBlack = false
						x = w.parent
						if x == root || !x.isBlack {
							x.isBlack = true
							break
						}
						if x == x.parent.left {
							w = x.parent.right
						} else {
							w = x.parent.left
						}
					} else {
						if w.right == nil || w.right.isBlack {
							w.left.isBlack = true
							w.isBlack = false
							rotateRightIntInterfaceTreeMap(w)
							w = w.parent
						}
						w.isBlack = w.parent.isBlack
						w.parent.isBlack = true
						w.right.isBlack = true
						rotateLeftIntInterfaceTreeMap(w.parent)
						break
					}
				} else {
					if !w.isBlack {
						w.isBlack = true
						w.parent.isBlack = false
						rotateRightIntInterfaceTreeMap(w.parent)
						if root == w.right {
							root = w
						}
						w = w.right.left
					}
					if (w.left == nil || w.left.isBlack) && (w.right == nil || w.right.isBlack) {
						w.isBlack = false
						x = w.parent
						if !x.isBlack || x == root {
							x.isBlack = true
							break
						}
						if x == x.parent.left {
							w = x.parent.right
						} else {
							w = x.parent.left
						}
					} else {
						if w.left == nil || w.left.isBlack {
							w.right.isBlack = true
							w.isBlack = false
							rotateLeftIntInterfaceTreeMap(w)
							w = w.parent
						}
						w.isBlack = w.parent.isBlack
						w.parent.isBlack = true
						w.left.isBlack = true
						rotateRightIntInterfaceTreeMap(w.parent)
						break
					}
				}
			}
		}
	}
}

// ForwardIterator represents a position in a tree map.
// It is designed to iterate a map in a forward order.
// It can point to any position from the first element to the one-past-the-end element.
type forwardIteratorIntInterfaceTreeMap struct {
	tree *intInterfaceTreeMap
	node *nodeIntInterfaceTreeMap
}

// Valid reports if an iterator's position is valid.
// In other words it returns true if an iterator is not at the one-past-the-end position.
func (i forwardIteratorIntInterfaceTreeMap) Valid() bool { return i.node != i.tree.endNode }

// Next moves an iterator to the next element.
// It panics if goes out of bounds.
func (i *forwardIteratorIntInterfaceTreeMap) Next() {
	if i.node == i.tree.endNode {
		panic("out of bound iteration")
	}
	i.node = successorIntInterfaceTreeMap(i.node)
}

// Prev moves an iterator to the previous element.
// It panics if goes out of bounds.
func (i *forwardIteratorIntInterfaceTreeMap) Prev() {
	i.node = predecessorIntInterfaceTreeMap(i.node)
	if i.node == nil {
		//panic("out of bound iteration")
	}
}

// Key returns a key at an iterator's position
func (i forwardIteratorIntInterfaceTreeMap) Key() int { return i.node.key }

// Value returns a value at an iterator's position
func (i forwardIteratorIntInterfaceTreeMap) Value() interface{} { return i.node.value }

// ReverseIterator represents a position in a tree map.
// It is designed to iterate a map in a reverse order.
// It can point to any position from the one-before-the-start element to the last element.
type reverseIteratorIntInterfaceTreeMap struct {
	tree *intInterfaceTreeMap
	node *nodeIntInterfaceTreeMap
}

// Valid reports if an iterator's position is valid.
// In other words it returns true if an iterator is not at the one-before-the-start position.
func (i reverseIteratorIntInterfaceTreeMap) Valid() bool { return i.node != nil }

// Next moves an iterator to the next element in reverse order.
// It panics if goes out of bounds.
func (i *reverseIteratorIntInterfaceTreeMap) Next() {
	if i.node == nil {
		panic("out of bound iteration")
	}
	i.node = predecessorIntInterfaceTreeMap(i.node)
}

// Prev moves an iterator to the previous element in reverse order.
// It panics if goes out of bounds.
func (i *reverseIteratorIntInterfaceTreeMap) Prev() {
	if i.node != nil {
		i.node = successorIntInterfaceTreeMap(i.node)
	} else {
		i.node = i.tree.beginNode
	}
	if i.node == i.tree.endNode {
		panic("out of bound iteration")
	}
}

// Key returns a key at an iterator's position
func (i reverseIteratorIntInterfaceTreeMap) Key() int { return i.node.key }

// Value returns a value at an iterator's position
func (i reverseIteratorIntInterfaceTreeMap) Value() interface{} { return i.node.value }


package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	num, _ := strconv.Atoi(scanner.Text())
	sum1 := num * (num - 1) / 2
	arr := make([]int, 0, num)
	for scanner.Scan() {
		e, _ := strconv.Atoi(scanner.Text())
		arr = append(arr, e)
	}
	sum2 := 0
	count := make(map[int]int)
	for _, v := range arr {
		sum2 += v
		if _, ok := count[v]; ok {
			count[v]++
		} else {
			count[v] = 1
		}
	}
	count1 := 0
	for k, v := range count {
		if v > 2 {
			fmt.Println("cslnb")
			return
		} else if v == 2 {
			if k == 0 {
				fmt.Println("cslnb")
				return
			}
			if v2, ok := count[k-1]; ok && v2 == v-1 {
				fmt.Println("cslnb")
				return
			}
			count1++
		}
	}
	if count1 > 1 {
		fmt.Println("cslnb")
		return
	}
	res := sum2 - sum1
	if res%2 == 0 {
		fmt.Println("cslnb")
	} else {
		fmt.Println("sjfnb")
	}
}

package main

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

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

	input.Scan()
	n, _ := strconv.Atoi(input.Text())
	result := false
	a := make([]int, n, n)
	z := 0
	double := 0
	nums := make(map[int]int)
	for i, _ := range a {
		input.Scan()
		a[i], _ = strconv.Atoi(input.Text())
		nums[a[i]] += 1
		if nums[a[i]] > 2 {
			result = true
		}
		if nums[a[i]] == 2 {
			z += 1
			double = a[i]
			if z > 1 || a[i] == 0 {
				result = true
			}
		}
	}
	if !result {
		_, fnd := nums[double-1]
		if fnd {
			result = true
		}
	}
	if !result {
		sort.Slice(a, func(i, j int) bool {
			return a[i] < a[j]
		})
		y := 0
		for i, x := range a {
			y += x - i
		}
		if y%2 == 0 {
			result = true
		}
	}
	if result {
		fmt.Println("cslnb")
	} else {
		fmt.Println("sjfnb")
	}
}

// Author: sighduck
// URL: https://codeforces.com/contest/1190/problem/B

package main

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

const (
	PlayerOneWins = "sjfnb"
	PlayerTwoWins = "cslnb"
)

func doesLegalFirstMoveExist(count map[int]int) bool {
	if count[0] >= 2 {
		return false
	}
	appearsTwiceOrMore := 0
	for elem, elemCount := range count {
		if elemCount > 2 {
			return false
		}
		if elemCount >= 2 {
			appearsTwiceOrMore += 1
		}
		if elemCount >= 2 && count[elem-1] > 0 {
			return false
		}
	}
	if appearsTwiceOrMore >= 2 {
		return false
	}
	return true
}

func Solve(n int, a []int) string {
	sum := int64(0)
	count := make(map[int]int)
	for _, elem := range a {
		sum += int64(elem)
		count[elem] += 1
	}
	legalFirstMoveExists := doesLegalFirstMoveExist(count)
	if !legalFirstMoveExists {
		return PlayerTwoWins
	}
	legalPermutationSum := int64(n-1) * int64(n) / int64(2)
	if (sum-legalPermutationSum)%2 == 0 {
		return PlayerTwoWins
	}
	return PlayerOneWins
}

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

	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &a[i])
	}
	fmt.Fscanf(reader, "\n")

	fmt.Fprintf(writer, "%s\n", Solve(n, a))
}

package main

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

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

	input.Scan()
	n, _ := strconv.Atoi(input.Text())
	result := false
	a := make([]int, n, n)
	z := 0
	nums := make(map[int]int)
	for i, _ := range a {
		input.Scan()
		a[i], _ = strconv.Atoi(input.Text())
		nums[a[i]] += 1
		if nums[a[i]] > 2 {
			result = true
		}
		if nums[a[i]] == 2 {
			z += 1
			if z > 1 || a[i] == 0 {
				result = true
			}
		}
	}
	if !result {
		sort.Slice(a, func(i, j int) bool {
			return a[i] < a[j]
		})
		y := 0
		for i, x := range a {
			y += x - i
		}
		if y%2 == 0 {
			result = true
		}
	}
	if result {
		fmt.Println("cslnb")
	} else {
		fmt.Println("sjfnb")
	}
}

package main

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

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

	input.Scan()
	n, _ := strconv.Atoi(input.Text())
	result := false
	a := make([]int, n, n)
	nums := make(map[int]int)
	for i, _ := range a {
		input.Scan()
		a[i], _ = strconv.Atoi(input.Text())
		nums[a[i]] += 1
		if nums[a[i]] > 2 {
			result = true
		}
	}
	if !result {
		sort.Slice(a, func(i, j int) bool {
			return a[i] < a[j]
		})
		y := 0
		for i, x := range a {
			y += x - i
		}
		if y%2 == 0 {
			result = true
		}
	}
	if result {
		fmt.Println("cslnb")
	} else {
		fmt.Println("sjfnb")
	}
}

package main

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

func distance(from, to, m int) int {
	if from > to {
		return m - from + to
	} else {
		return to - from
	}
}
func check(a []int, x, m int) bool {
	maxval := 0
	for _, item := range a {
		dist := distance(item, maxval, m)
		if dist <= x {
			continue
		}
		if item >= maxval {
			maxval = item
		} else {
			return false
		}
	}
	return true
}

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

	input.Scan()
	n, _ := strconv.Atoi(input.Text())
	result := true
	a := make([]int, n, n)
	nums := make(map[int]int)
	for i, _ := range a {
		input.Scan()
		a[i], _ = strconv.Atoi(input.Text())
		nums[a[i]] += 1
		if nums[a[i]] > 2 {
			result = false
		}
	}
	if result {
		sort.Slice(a, func(i, j int) bool {
			return a[i] < a[j]
		})
		y := 0
		for i, x := range a {
			y += x - i
		}
		if y%2 == 1 {
			result = false
		}
	}
	if result {
		fmt.Println("cslnb")
	} else {
		fmt.Println("sjfnb")
	}
}

package main

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

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

	input.Scan()
	n, _ := strconv.Atoi(input.Text())
	result := false
	a := make([]int, n, n)
	z := 0
	nums := make(map[int]int)
	for i, _ := range a {
		input.Scan()
		a[i], _ = strconv.Atoi(input.Text())
		nums[a[i]] += 1
		if nums[a[i]] > 2 {
			result = true
		}
		if nums[a[i]] == 2 {
			z += 1
			if z > 1 {
				result = true
			}
		}
	}
	if !result {
		sort.Slice(a, func(i, j int) bool {
			return a[i] < a[j]
		})
		y := 0
		for i, x := range a {
			y += x - i
		}
		if y%2 == 0 {
			result = true
		}
	}
	if result {
		fmt.Println("cslnb")
	} else {
		fmt.Println("sjfnb")
	}
}

package main

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

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

	input.Scan()
	n, _ := strconv.Atoi(input.Text())
	result := false
	a := make([]int, n, n)
	z := 0
	nums := make(map[int]int)
	for i, _ := range a {
		input.Scan()
		a[i], _ = strconv.Atoi(input.Text())
		nums[a[i]] += 1
		if nums[a[i]] > 2 {
			result = true
		}
		if nums[a[i]] == 2 && z > 1 {
			result = true
			z += 1
		}
	}
	if !result {
		sort.Slice(a, func(i, j int) bool {
			return a[i] < a[j]
		})
		y := 0
		for i, x := range a {
			y += x - i
		}
		if y%2 == 0 {
			result = true
		}
	}
	if result {
		fmt.Println("cslnb")
	} else {
		fmt.Println("sjfnb")
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	num, _ := strconv.Atoi(scanner.Text())
	scanner.Scan()
	arr := strings.Split(scanner.Text(), " ")
	sum1 := 0
	for i := 0; i < num; i++ {
		sum1 += i
	}
	sum2 := 0
	count := make(map[int]int)
	for _, v := range arr {
		v2, _ := strconv.Atoi(v)
		sum2 += v2
		if _, ok := count[v2]; ok {
			count[v2]++
		} else {
			count[v2] = 1
		}
	}
	count1 := 0
	for k, v := range count {
		if v > 2 {
			fmt.Println("cslnb")
			return
		} else if v == 2 {
			if k == 0 {
				fmt.Println("cslnb")
				return
			}
			if v2, ok := count[k-1]; ok && v2 == v -1 {
				fmt.Println("cslnb")
				return
			}
			count1++
		}
	}
	if count1 > 1 {
		fmt.Println("cslnb")
		return
	}
	res := sum2 - sum1
	if res%2 == 0 {
		fmt.Println("cslnb")
	} else {
		fmt.Println("sjfnb")
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	num, _ := strconv.Atoi(scanner.Text())
	scanner.Scan()
	arr := strings.Split(scanner.Text(), " ")
	sum1 := 0
	for i := 0; i < num; i++ {
		sum1 += i
	}
	sum2 := 0
	count := make(map[int]int)
	for _, v := range arr {
		v2, _ := strconv.Atoi(v)
		sum2 += v2
		if _, ok := count[v2]; ok {
			count[v2]++
		} else {
			count[v2] = 1
		}
	}
	count1 := 0
	for k, v := range count {
		if v > 2 {
			fmt.Println("cslnb")
			return
		} else if v == 2 {
			if v2, ok := count[k-1]; ok && v2 == v -1 {
				fmt.Println("cslnb")
				return
			}
			count1++
		}
	}
	if count1 > 1 {
		fmt.Println("cslnb")
		return
	}
	res := sum2 - sum1
	if res%2 == 0 {
		fmt.Println("cslnb")
	} else {
		fmt.Println("sjfnb")
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	num, _ := strconv.Atoi(scanner.Text())
	scanner.Scan()
	arr := strings.Split(scanner.Text(), " ")
	sum1 := 0
	for i := 0; i < num; i++ {
		sum1 += i
	}
	sum2 := 0
	for _, v := range arr {
		v2, _ := strconv.Atoi(v)
		sum2 += v2
	}
	res := sum2 - sum1
	if res%2 == 0 {
		fmt.Println("cslnb")
	} else {
		fmt.Println("sjfnb")
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	num, _ := strconv.Atoi(scanner.Text())
	scanner.Scan()
	arr := strings.Split(scanner.Text(), " ")
	sum1 := 0
	for i := 0; i < num; i++ {
		sum1 += i
	}
	sum2 := 0
	count := make(map[int]int)
	for _, v := range arr {
		v2, _ := strconv.Atoi(v)
		sum2 += v2
		if _, ok := count[v2]; ok {
			count[v2]++
		} else {
			count[v2] = 1
		}
	}
	count1 := 0
	for k, v := range count {
		if v > 2 {
			fmt.Println("cslnb")
			return
		} else if v == 2 {
			if v2, ok := count[k-1]; ok && v2 == v -1 {
				fmt.Println("cslnb")
				return
			}
			count1++
		}
	}
	if count1 > 0 {
		fmt.Println("cslnb")
		return
	}
	res := sum2 - sum1
	if res%2 == 0 {
		fmt.Println("cslnb")
	} else {
		fmt.Println("sjfnb")
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	num, _ := strconv.Atoi(scanner.Text())
	scanner.Scan()
	arr := strings.Split(scanner.Text(), " ")
	sum1 := 0
	for i := 0; i < num; i++ {
		sum1 += i
	}
	sum2 := 0
	count := make(map[int]int)
	for _, v := range arr {
		v2, _ := strconv.Atoi(v)
		sum2 += v2
		if _, ok := count[v2]; ok {
			count[v2]++
		} else {
			count[v2] = 1
		}
	}
	for k, v := range count {
		if v > 2 {
			fmt.Println("cslnb")
			return
		} else if v == 2 {
			if v2, ok := count[k-1]; ok && v2 == v -1 {
				fmt.Println("cslnb")
				return
			}
		}
	}
	res := sum2 - sum1
	if res%2 == 0 {
		fmt.Println("cslnb")
	} else {
		fmt.Println("sjfnb")
	}
}

// Author: sighduck
// URL: https://codeforces.com/contest/1190/problem/B

package main

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

const (
	PlayerOneWins = "sjfnb"
	PlayerTwoWins = "cslnb"
)

func doesLegalFirstMoveExist(count map[int]int) bool {
	if count[0] >= 2 {
		return false
	}
	for elem, _ := range count {
		if elem != 0 {
			count[elem] -= 1
			if count[elem-1] < 2 && count[elem+1] < 2 && count[elem] < 2 {
				return true
			}
			count[elem] += 1
		}
	}
	return false
}

func Solve(n int, a []int) string {
	sum := int64(0)
	count := make(map[int]int)
	for _, elem := range a {
		sum += int64(elem)
		count[elem] += 1
	}
	legalFirstMoveExists := doesLegalFirstMoveExist(count)
	if !legalFirstMoveExists {
		return PlayerTwoWins
	}
	legalPermutationSum := int64(n-1) * int64(n) / int64(2)
	if (sum-legalPermutationSum)%2 == 0 {
		return PlayerTwoWins
	}
	return PlayerOneWins
}

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

	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &a[i])
	}
	fmt.Fscanf(reader, "\n")

	fmt.Fprintf(writer, "%s\n", Solve(n, a))
}

// Author: sighduck
// URL: https://codeforces.com/contest/1190/problem/B

package main

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

const (
	PlayerOneWins = "sjfnb"
	PlayerTwoWins = "cslnb"
)

func Solve(n int, a []int) string {
	sum := int64(0)
	count := make(map[int]int)
	for _, elem := range a {
		sum += int64(elem)
		count[elem] += 1
	}
	legalFirstMoveExists := false
	for _, elem := range a {
		count[elem] -= 1
		if count[elem-1] < 2 && count[elem+1] < 2 {
			legalFirstMoveExists = true
		}
	}
	if !legalFirstMoveExists {
		return PlayerTwoWins
	}
	legalPermutationSum := int64(n-1) * int64(n) / int64(2)
	if (sum-legalPermutationSum)%2 == 0 {
		return PlayerTwoWins
	}
	return PlayerOneWins
}

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

	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &a[i])
	}
	fmt.Fscanf(reader, "\n")

	fmt.Fprintf(writer, "%s\n", Solve(n, a))
}


package main

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

var in = bufio.NewScanner(os.Stdin)

func readInt() int {
	if !in.Scan() {
		panic(in.Err())
	}
	res := 0
	for _, b := range in.Bytes() {
		res = res*10 + int(b-'0')
	}
	return res
}

func main() {
	in.Split(bufio.ScanWords)
	n := readInt()
	m := make(map[int]int)
	for i := 0; i < n; i++ {
		m[readInt()]++
	}
	for _, c := range m {
		if c%2 == 1 {
			fmt.Println("Conan")
			return
		}
	}
	fmt.Println("Agasa")
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	var save = make([]int, n)
	var cnt = make(map[int]int)
	for i := range save {
		fmt.Scan(&save[i])
		cnt[save[i]]++
	}

	var keys = []int{}
	for k := range cnt {
		keys = append(keys, k)
	}
	sort.Ints(keys)
	for i := len(keys) - 1; i >= 0; i-- {
		if cnt[keys[i]]%2 == 1 {
			fmt.Println("Conan")
			return
		}
	}
	fmt.Println("Agasa")
}

package main

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

func Init() {
}

func Solve(io *FastIO) {
	N := io.NextInt()
	A := io.NextIntArray(N)

	freq := make(map[int]int)
	for _, v := range A {
		freq[v]++
	}

	for _, v := range freq {
		if v & 1 == 1 {
			io.Println("Conan")
			return
		}
	}
	io.Println("Agasa")
}

type FastIO struct {
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}

func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = (res * 10) + int(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = (res * 10) + int64(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}

func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextInt()
	}
	return arr
}

func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}

func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextLong()
	}
	return arr
}

func (io *FastIO) NextString() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) Println(args ...interface{}) {
	io.writer.WriteString(fmt.Sprintln(args...))
}

func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}

func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}

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

func IsLineBreakChar(c byte) bool {
	switch c {
		case 0, '\n', '\r':
			return true
		default:
			return false
	}
}

func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}
	Init()
	Solve(&io)
	io.FlushOutput()
}

package main

import "fmt"

func main() {
	n := 0
	fmt.Scan(&n)

	umap := make(map[int]int)

	arr := make([]int, 0, n)
	ma := int(-1e7)
	for i:= 0; i<n; i++{
		x := 0
		fmt.Scan(&x)

		if umap[x] == 0  {
			arr = append(arr, x)
		}
		umap[x] += 1

		if ma < x {
			ma = x
		}
	}

	ans := "Agasa"
	if umap[ma] & 1 == 1 {
		ans = "Conan"
	}else {
		for _, v := range arr {
			if(umap[v] & 1 == 1) {
				ans = "Conan"
				break
			}
		}
	}
	fmt.Println(ans)
}

package main

import (
	"fmt"
	"sort"
)

func isWin(cards []int) bool {
	if len(cards) == 0 {
		return false
	}
	max := cards[len(cards)-1]
	var lastMax = len(cards) - 1
	for lastMax > 0 && cards[lastMax-1] == max {
		lastMax--
	}
	numMax := len(cards) - lastMax
	if numMax%2 == 1 {
		return true
	}
	return isWin(cards[:lastMax])
}

func main() {
	var n int
	fmt.Scan(&n)

	cards := make([]int, n)
	for i := range cards {
		fmt.Scan(&cards[i])
	}

	sort.Ints(cards)

	if isWin(cards) {
		fmt.Println("Conan")
	} else {
		fmt.Println("Agasa")
	}
}

package main

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

func solve() {
	n := readInt()
	a := readIntArray(n)
	freq := make(map[int]int)
	for _, v := range a {
		freq[v]++
	}
	b := make([]int, 0)
	for k, _ := range freq {
		b = append(b, k)
	}
	if len(b) == 1 {
		cnt := freq[b[len(b)-1]]
		if cnt%2 == 1 {
			fmt.Println("Conan")
		} else {
			fmt.Println("Agasa")
		}
	} else {
		for i := 0; i < len(b); i++ {
			cnt := freq[b[i]]
			if cnt%2 == 1 {
				fmt.Println("Conan")
				return
			}
		}
		fmt.Println("Agasa")
	}
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

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

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// IO

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

package main

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

func solve() {
	n := readInt()
	a := readIntArray(n)
	freq := make(map[int]int)
	for _, v := range a {
		freq[v]++
	}
	b := make([]int, 0)
	for k, _ := range freq {
		b = append(b, k)
	}
	if len(b) == 1 {
		cnt := freq[b[len(b)-1]]
		if cnt%2 == 1 {
			fmt.Println("Conan")
		} else {
			fmt.Println("Agasa")
		}
	} else {
		fmt.Println("Conan")
	}
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

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

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// IO

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}