Gcd and lcm question issue

the above is a code for finding the gcd and lcm of two numbers A and B with the given constraints:

1 <= T <= 10^4
1 <= A <= 10^8
1 <= B <= 10^8

so in this lcm can exceed 10^9 but not A,B and hcf
so why if i write long long int datatype only for the lcm but not for A,B and gcd it is giving incorrect answer?

how does the conversion from int to long long int happen?

please share the question link
so that i can check for myself how the code is not working and what code will work

https://ide.codingblocks.com/s/289786 in this the question link is given

#include <iostream>
using namespace std;

int gd(int a ,int b){
    if( b > a) return gd( b, a);
    if( b == 0 ) return a;
    return gd( b , a%b);
}
int main() {
    int t ;
    cin >> t;
    while(t--){
        int a , b;
        cin >> a >> b;
        int gcd  = gd(a , b);
        long long int lcm = ((long long)a*(long long)b)/gcd;
        cout << lcm <<" "<<gcd<<"\n";
    }
}

this code gives correct answer
the problem is when u are multiplying int
the answer will be in int range
but which is wrong for large test cases
so basically type cast those to long long
multiplication will be long long
then lcm comes out to be correct