```go
package main
import (
"bufio"
"os"
"sort"
"strconv"
"strings"
)
type FastScanner struct {
r *bufio.Reader
s []string
i int
}
func NewFastScanner() *FastScanner {
return &FastScanner{r: bufio.NewReader(os.Stdin)}
}
func (fs *FastScanner) next() string {
if fs.i >= len(fs.s) {
line, _ := fs.r.ReadString('\n')
fs.s = strings.Fields(line)
fs.i = 0
}
res := fs.s[fs.i]
fs.i++
return res
}
func (fs *FastScanner) nextInt() int {
res, _ := strconv.Atoi(fs.next())
return res
}
type Query struct {
limit int
a int
b int
idx int
}
type DSU struct {
parent []int
}
func NewDSU(n int) *DSU {
parent := make([]int, n+1)
for i := 0; i <= n; i++ {
parent[i] = i
}
return &DSU{parent: parent}
}
func (d *DSU) find(x int) int {
if d.parent[x] != x {
d.parent[x] = d.find(d.parent[x])
}
return d.parent[x]
}
func (d *DSU) union(x, y int) {
px := d.find(x)
py := d.find(y)
if px != py {
d.parent[px] = py
}
}
func main() {
fs := NewFastScanner()
t := fs.nextInt()
out := bufio.NewWriter(os.Stdout)
defer out.Flush()
for tc := 0; tc < t; tc++ {
n := fs.nextInt()
m := fs.nextInt()
h := make([]int, n+1)
for i := 1; i <= n; i++ {
h[i] = fs.nextInt()
}
graph := make([][]int, n+1)
for i := 0; i < m; i++ {
u := fs.nextInt()
v := fs.nextInt()
graph[u] = append(graph[u], v)
graph[v] = append(graph[v], u)
}
q := fs.nextInt()
queries := make([]Query, q)
for i := 0; i < q; i++ {
a := fs.nextInt()
b := fs.nextInt()
e := fs.nextInt()
limit := h[a] + e
queries[i] = Query{limit: limit, a: a, b: b, idx: i}
}
nodes := make([]int, n)
for i := 0; i < n; i++ {
nodes[i] = i + 1
}
sort.Slice(nodes, func(i, j int) bool {
return h[nodes[i]] < h[nodes[j]]
})
sort.Slice(queries, func(i, j int) bool {
return queries[i].limit < queries[j].limit
})
dsu := NewDSU(n)
active := make([]bool, n+1)
answers := make([]string, q)
ptr := 0
for _, query := range queries {
for ptr < n && h[nodes[ptr]] <= query.limit {
u := nodes[ptr]
active[u] = true
for _, v := range graph[u] {
if active[v] {
dsu.union(u, v)
}
}
ptr++
}
if active[query.a] && active[query.b] && dsu.find(query.a) == dsu.find(query.b) {
answers[query.idx] = "YES"
} else {
answers[query.idx] = "NO"
}
}
for i := 0; i < q; i++ {
out.WriteString(answers[i] + "\n")
}
}
}
```