Minimize Least Used Binary Bits in Fractions Introduction
For a given rational number r, find a pair of integers p,q so that p/q=r and the number of less used bits in p and q are minimized (details below).
Challenge
A positive rational number r can be expressed as the ratio of two positive integers, r=p/q. The representation is not unique. For each of these representations, both p and q can be expressed in its binary form and the number of 0s and 1s in the representation can be counted (not including leading zeros).
We count the number of appearance of the less appeared digit for both p and q (denoted g(p) and g(q)) and finally define f(p,q)=max(g(p),g(q)).
For example, the number 35 can be written as 35/1 or 175/5, and we convert both the numerator and the denominator to binary. Then we can count
35 -&gt; 100011, 3 zeros, 3 ones. g(35)=min(3,3)=3
 1 -&gt;      1, 0 zero ,  1 one.  g(1)=min(1,0)=0

f(35,1)=max(g(35),g(1))=3.

And for 175/5
175 -&gt; 10101111. 2 zeros, 6 ones. g(175)=min(2,6)=2
  5 -&gt;      101. 1 zero,  2 ones.   g(5)=min(1,2)=1.

f(175,5)=max(g(175),g(5))=2.

Therefore, if we want to minimize f(p,q) while keeping the rate of p/q constant, p=175,q=5 is a better choice than p=35,q=1. An even better choice is p=1015,q=29 since f(1015,29)=1. It is also easy to prove that there are no valid choice that makes f(p,q) equals 0, so this the optimal choice.
Your task is to write a full program or function that computes a choice of (p,q) for a given rational number r such that f(p,q) is minimized (sub-optimal solutions are OK but there are penalties), while keeping the program as short as possible.
Test cases
The outputs are not unique.
Input
Output

63/1
63/1 0

17/9
119/63 1

35/1
1015/29 1

563/1
2815/5 2

You may also wish to see whether you can get an answer without penalty(see below) for 595/1.
Scoring
Your score will be composed of two parts: the code-length and the penalties. The code-length is measured in bytes.
The penalties are calculated by running your program on all test cases in the given test set. For each r in the test set, if your program outputs p,q, you get a penalty of max(f(p,q)-2,0). That is, you get no penalty (nor bounty) for any answer that gives a f value less than or equal to 2.
The final score is calculated by final_penalty*codelength^(1/4), with lower score better.
Test set
The test set for calculating the penalty can be found in this
pastebin.
Basically, it contains all rational numbers which when expressed in reduced fraction p/q has the property 128&gt;p&gt;q (and of course, (p,q) coprime), along with all integers from 128 to 1023(inclusive). The second column in the pastebin are the f(p,q) calculated by a naive method. The final line in the pastebin shows the total penalty of this naive method. It is 2343.
Specs

Input can be given in any reasonable form. For example, a rational if your program supports it, or a tuple or a list of the numerators and denominators in any order (and you should assume them to be coprime). Same flexiblility for output.
You need to output p and q in a reasonable form and also f(p,q) (To avoid 0-byte programs, thanks to @Lynn).
You should be able to score your own program (Thanks for the suggestion by @user202729). So in your answer, please specify all of the following: the final penalty, the code length in bytes, and the score. Only the score needs to be included in the title of your answer.
Node.js, Score = 7873
This is both naive and rather long...

Code size = 129 bytes
Total penalty = 2336
Score = round(1291/4 * 2336) = 7873

Takes input as [p, q]. Returns [p', q', f(p, q)].

f=(a,r=[k=6e3])=&gt;k--?f(a,(i=Math.max(...a.map(n=&gt;(g=n=&gt;n?g(n&gt;&gt;1,n&amp;1?++o:++z):o&lt;z?o:z)(a=(p=a,n*k),o=z=0))))&gt;r[2]?r:[p,a,i],k--):r

Try it online! for the test cases
or compute the total penalty by processing the whole test set

Alternate version, Score = 8426
A modified version to reach a total penalty of 2330. But it's not worth it...

Code size = 171 bytes
Total penalty = 2330
Score = round(1711/4 * 2330) = 8426

Same I/O format as the main version.
f=(a,r=[k=5e3])=&gt;k--?f(a,(i=Math.max(...a.map(n=&gt;(g=n=&gt;n?g(n&gt;&gt;1,n&amp;1?++o:++z):o&lt;z?o:z)(a=(p=a,n*([7007,7901,16239,32695,130527,261599][k]||k-5)),o=z=0))))&gt;r[2]?r:[p,a,i]):r

Try it online!
It includes some hardcoded values for the highest multipliers. They were found by generating all bitmasks m with up to 32 bits and no more than 5 0's, keeping the values for which m mod p = 0, checking the score of q * m / p and finally doing the same operation with the inverted bitmask of m of the same length (no more than 5 1's with all other bits set to 0).