For Mario I can't recall specifically which I played first, since several were among my first video games in general and I started playing them when I was like 2. So it was probably either Super Mario Bros. 1 or 2 for the NES, but there's also a chance it was Super Mario All-Stars or World.
As for Sonic, that'd be Sonic Adventure on Dreamcast. Technically some demo disc that included just Emerald Coast among other game demos before I got the full game. I remember just running through that level a lot, aha. That was also around when I got a Sonic plush, and there was just something really cool about having a toy of a game character at the time, considering that was before video game merch was widespread at all.
First Mario Game: Super Mario Bros 1 in a pirate nes console. ;-;
First Sonic Game: Sonic 2 in emulator.
Well don't feel bad about first playing SMB on a Dendy or whatever the hell you played it on. At least you sort of grew up with the real thing! All I grew up with were shitty half completed flash games! Like most of them weren't even finished! If only I knew about Emulators/ROMs back then...
my first mario game: a mario reskin of the great giana sisters (super mario all-stars if you only count nintendo games)
my first sonic game: sonic the hedgehog (not the loading screen simulator of course)
random avatar everyime you reload wheeee
Since I grew up playing my dad's old consoles for the most time, it's hard to remember the exact first when it comes to this stuff. Since I've played both all the earliest Mario games (8-bit and 16-bit counterparts), plus the Game Boy games. It could easily just have been SMW, but maybe it was SMB1 too. (So either SMB1 or SMW).
As for Sonic, it was the first Game Gear game. It's easier to know that, since I haven't played nearly as many Sonic games as I've played Mario games.