Efficiently Computing Sparse Fourier Transforms of $q$-ary Functions