After you receive the flute, you go through the Vast Poni Canyon so you can reach the altar and summon the legendary pokémon.
Enter Vast Poni Canyon
After you get the flute, go to Ancient Poni Path and try to go north. You have to battle a Team Skull Grunt who has a level 45 Ekans. You get 1440 Pokédollars for winning.
Next, you have to battle a Team Skull Grunt who has a level 45 Fomantis, a level 45 Raticate, a level 45 Houndour, a level 45 Golbat, and a level 45 Mareanie. You get 1440 Pokédollars for winning.
After the battle, you get Poisonium Z, and Lillie heals your pokémon.
Before you go to Vast Poni Canyon, go northeast and check behind the stone pillar to find a hidden Max Potion.
Then go north to enter Vast Poni Canyon.
Go north toward Hapu. After a cutscene, you battle Ultra Recon Squad Dulse (in Ultra Sun) or Ultra Recon Squad Soliera (in Ultra Moon), who has a level 49 Poipole. You get 588 Pokédollars for winning.
Afterward, go north. Before you talk to Lillie, go to the left and check under the branch to the left of her, and you will crawl through. You find TM93 Wild Charge.
Check on the branch to go back to the previous area, then talk to Lillie. She gives you a Max Revive, and she heals up your pokémon.
Then go into the cave.
To the right, you must battle Veteran Harry. He has a level 47 Beheeyem and a level 47 Banette. You get 4136 Pokédollars for winning.
Go east and you can battle Backpacker Perdy. She has a level 45 Spinda. You get 1080 Pokédollars for winning.
Break through the rocks south of the Backpacker and check on the hole to go through. There is a Protein there.
Go to the left and jump down the ledge, then go south up the ramp. Near the top of the ramp, on a rock to the left, there is a hidden Nugget.
To the right, break through the boulders to get the Max Potion beyond.
To the left, you can battle Ace Duo Kent and Aimee. They have a level 47 Alolan Ninetales and a level 47 Alolan Sandslash. You get 6392 Pokédollars for winning.
Go west from the Ace Trainers and break the boulder in the path, then go south to go outside.
Go southeast through the grass to find a Max Revive.
Then follow the path west. Before you enter the cave, look for a narrow path to the right of the cave door. Go north along that path and check on the small rock at the end to find a hidden X Attack.
Go back to the cave entrance and go in.
Check behind the rock to the north to find an X Defense.
To the left you can battle Hiker Zachary. He has a level 46 Kabutops and a level 46 Tyrantrum. You get 1472 Pokédollars for winning.
Go to the left of the Hiker, then go south to exit the cave.
Go to the right and crawl into the hole. Go east through the narrow path and you will battle Veteran Lynn. She has a level 48 Xatu, a level 48 Kangaskhan, and a level 48 Dewgong. You get 4224 Pokédollars for winning.
North of the Veteran, there is an Escape Rope.
Southeast of the rocky ground, you can battle Ace Trainer Junko. She has a level 45 Lilligant and a level 46 Weavile. You get 3128 Pokédollars for winning.
Southeast of the rocky ground, you can battle Ace Trainer Junko. She has a level 47 Mawile and a level 48 Weavile. You get 3264 Pokédollars for winning.
Check on the hole south of the Ace Trainer to go outside. You find TM99 Dazzling Gleam.
There is a hidden X Sp. Atk on the right side of the rock to the right.
Now go back the way you came and approach the bridge on the left. During a cutscene, Lillie wll heal your pokemon. Afterward, you can go back onto the bridge to find a Poké Finder spot.
Go north into the cave next to Lillie.
Go down the ramp to the left. There is a Nugget between some pokémon dens.
Go down the ramp to the right. Go up above the boulder and have Machamp push it all the way down until it falls into a hole. There is a Full Restore to the left.
Go south and have Machamp push the boulder to the right.
Go southeast to exit the cave. Go west through the grass to find a Dusk Ball.
Go back into the cave. Then go north and have Machamp push the boulder north. There is a ladder to the right. Check on it to climb up. In this area, you can battle Scientist Ikaika. He has a level 46 Magnezone. You get 2208 Pokédollars for winning.
Go east to exit the cave. To the right, you can battle Punk Girl Anna. She has a level 46 Scrafty. You get 1472 Pokédollars for winning.
Go east across the bridge. On the east side of the bridge, you can battle Punk Guy Adam. He has a level 46 Pangoro and a level 46 Crawdaunt. You get 1472 Pokédollars for winning.
Go east and cross the bridge. There is a hidden PP Max to the right of the bridge.
There is a tree branch going north from the end of the bridge. Go down along the tree branch to reach a grassy area. Go north from there, then go west down the slope. You can go south into the cave and push the boulder to the right to create a shortcut to the exit.
Go north to return to the previous area. Go east up the slope. Go southeast past the tree branch. You can go through the grass, or you can go to the left up a slope and jump down a ledge to go southwest and get a Full Heal.
East of the Full Heal, you can battle Black Belt Curtis. He has a level 47 Poliwrath. You get 1504 Pokédollars for winning.
Now go northwest, and go west down the slope.
Before you go north to battle the Ace Trainer, check on the branches southwest of him to enter a new area. Go northwest past the grass and you can battle a Team Skull Grunt who has a level 46 Pawniard. You get 1472 Pokédollars for winning.
Go northwest and enter the cave.
Go north in the water and you can battle Black Belt Terry. He has a level 47 Crabominable. You get 1504 Pokédollars for winning.
Go west from there and you will find a Rare Candy.
Go south from there and you will battle Surfer Joshah. He has a level 47 Golduck. You get 1128 Pokédollars for winning.
Go southwest from there to find TM35 Flamethrower.
Go back the way you came until you see the Ace Trainer to the north. Go north and you have to battle Ace Trainer Hiroshi. He has a level 47 Alolan Graveler and a level 48 Lapras. You get 3264 Pokédollars for winning.
Go north and you have to battle Veteran Heather. She has a level 48 Talonflame, a level 48 Wailord, and a level 48 Glaceon. You get 4224 Pokédollars for winning.
Go north and you have to battle Veteran Eric. He has a level 48 Noctowl, a level 48 Flygon, a level 48 Slowking, and a level 48 Gengar. You get 4224 Pokédollars for winning.
Go north and Lillie will heal your pokémon.
Go north to enter the cave. You will be asked if you are ready for the trial. You can say No if you want to prepare first.
Go north and you will feel a piercing gaze. Go farther northeast and you must battle a level 42 Jangmo-o. Since this is a trial, you can't catch it, so just KO it.
Afterward, you feel another gaze. Go to the right and enter the small cave to get TM02 Dragon Claw.
Leave the cave and go northwest past a small rock on the left. You will have to battle a level 44 Hakamo-o. Again, you can't catch it, so just KO it.
After that, you feel another gaze. Go north to the pedestal and take the Z-Crystal.
You will have to battle a level 49 Totem Kommo-o. He can call ally pokémon into battle, such as Hakamo-o and Noivern.
After the battle, you get Dragonium Z.
Go north to reach the Altar of the Sunne/Moone. Lillie will heal your pokémon.
After that, go up the stairs to reach the top.
After a cutscene, go to the side, then up, to stand on the proper spot. When asked if you will blow the flute, say yes.
After a cutscene, you must defeat Necrozma. You can't catch it, so just focus on defeating it. If you are playing Pokémon Ultra Sun, it's weak to Ground, Ghost, Fire, and Dark. If you're playing Pokémon Ultra Moon, it's weak to Ghost and Dark.
After the battle, there will be a cutscene.
Talk to the Ultra Recon Squad and you can go on the Ultra Warp Ride to go after Necrozma. You can say "Not now" if you want to go prepare. You can fly back here on Charizard when you are ready.