Hypothesis testing using pairwise distances and associated kernels (with Appendix)