n, m = gets.split.map(&:to_i)

dmat = Array.new(n*n){false}

n.times{|i|
  dmat[n*i+i] = true
}
m.times{
  i, j = gets.split.map(&:to_i)
  dmat[i*n+j] = dmat[j*n+i] = true
}

tmat = dmat
loop do
  n.times{|i|
    n.times{|j|
      sum = false
      n.times{|k|
        sum = sum || (tmat[i*n+k] && tmat[k*n+j])
      }
      dmat[i*n+j] = sum
    }
  }
  break if tmat == dmat
  tmat = dmat
end

q = gets.to_i

q.times{
  s, t = gets.split.map(&:to_i)
  if dmat[s*n+t]
    puts "yes"
  else
    puts "no"
  end
}