Unfortunately there is no bullet proof way. If you go to one of the more detailed usage statistics by model reports (I can't provide links, those are usually paid) you will notice that there is a lot of fragmentation and no one sub-model has more than very few usage percentages, and that's before OS version is taken into consideration. Note that for each main model e.g. Galaxy S8 there are more than a few sub models based on radio type, main processor, memory etc.
If your application is fairly simple (no hardware dependency for example, but even this is tricky since some graphical features do use dedicated hardware accelerations) you can probably get away with testing on one type of model out of sub-models based on usage statistics.
One of the many options for remote lab with real devices, or crows sourced testing, are good for covering the top used models, but again you will probably fail to get 100% coverage.
The bottom line is that you simply cannot test all combinations unless you purchase each and every one of them, probably more than one device of each model since re-installing the OS will bias your results at best and is impossible for some phones-OS combinations.