If q is empty then result is empty.