The Double-Castle Numbers™ Introduction

A double-castle number&trade; is a positive integer number that has a pattern of $$\underbrace{a\cdots a}_{m\text{ }a\text{s}}b\underbrace{a\cdots a}_{m\text{ }a\text{s}}b\underbrace{a\cdots a}_{m\text{ }a\text{s}}\underbrace{a\cdots a}_{n\text{ }a\text{s}}b\underbrace{a\cdots a}_{n\text{ }a\text{s}}b\underbrace{a\cdots a}_{n\text{ }a\text{s}}$$
Where \$m&gt;0\$, \$n&gt;0\$ and \$a-b=1\$ are all non-negative integers, when represented in an integer base \$B\$ where \$B\ge2\$. It is so named because a bar chart representing the base-\$B\$ digits of such a number resembles two castles of the same height place- side by side.

For example, \$7029\$* is a double-castle number because when represented in base 2 it becomes \$1101101110101_2\$, which can be split into \$11011011\$ and \$10101\$. 



This is the case when \$m=2\$, \$n=1\$, \$a=1\$, \$b=0\$ and \$B=2\$.

\$305421994212\$ is also a double-castle number because when represented in base 8 it becomes \$4343444344344_8\$, which can be split into \$43434\$ and \$44344344\$. 



This is the case when \$m=1\$, \$n=2\$, \$a=4\$, \$b=3\$ and \$B=8\$.

For \$a&gt;=10\$, \$a\$ should be treated as a single base-\$B\$ "digit" with the value of \$a\$ in base-10. \$206247763570426655730674346\$ is a double-castle number in base-16, whose representation in base-16 is \$\text{AA9AA9AAAAAA9AAAA9AAAA}_{16}\$. Here, \$a=10\$ but is treated as a single digit \$(10)_{16}=\text{A}_{16}\$.



This is the case when \$m=2\$, \$n=4\$, \$a=10\$, \$b=9\$ and \$B=16\$.

Challenge

Write a program or function that, given integers \$m&gt;0\$, \$n&gt;0\$, \$1\le a&lt;B\$ and \$B\ge2\$, calculate the corresponding double-castle number&trade; and output it in base-10.

Test Cases

The input below are in base-10, but in the case say when \$a=11\$ and \$B=12\$ the input should be understood as \$B_{12}\$.

m, n, a,  B  =&gt; Output
1, 1, 1,  2  =&gt; 693
2, 1, 1,  2  =&gt; 7029
1, 2, 3,  4  =&gt; 62651375
1, 2, 4,  8  =&gt; 305421994212
1, 4, 7,  10 =&gt; 7676777776777767777
2, 4, 8,  16 =&gt; 164983095594247313234036872
2, 4, 10, 16 =&gt; 206247763570426655730674346


Winning Condition

This is a code-golf challenge, the shortest submission in each language wins. No standard loopholes allowed.

*7029 comes from my ID minus it written reversed.
Python 2, 83 81 79 72 bytes

-9 bytes thanks to @ovs!
-2 bytes thanks to @dingledooper!



m,n,a,B=input()
r=0
for s in n,m+n,m,m:r+=B**n;n-=~s
print~-B**n/~-B*a-r


Try it online!

Calculate aaaa...aaa in base B, then subtract 1 at the appropriate digits.