Replace all pi question

#include <bits/stdc++.h>
using namespace std;

string replacePi(string s)
{
if (s.size() <= 1)
{
return s;
}

if (s.substr(0, 2) == "pi")
{
    string ros = replacePi(s.substr(2));
    return "3.14" + ros;
}

string ros = replacePi(s.substr(1));
return s[0] + ros;

}

int main()
{
int testCases;
cin >> testCases;
while (testCases–)
{
string s;
cin >> s;

    cout << replacePi(s) << endl;
}

return 0;

}

sir i cannot understand this code and why do we wright s[0] what is the use of it

and how does my program execute after the line string ros

s.substr(1)
provides u subtring from 1 to s.size()
s.substr(left, len)
provided substring from lef , left+ len
eg:
xabpixx3.15x
replacePi(s.substr(1));
ros = abpixx3.15x
then s.susbtr(0,2) is not pi
so ros = bpixx3.15x
then s.substr(0,2) is not pi
ros = pixx3.15x
then s.substr(0,2) is pi
ros = xx3.15x
…
goes up till base case is it
then the final stirng is formed