Hello!
Thank you for the query.
The thing coming out from your anus are most probably hemorrhoids or rectal mucosa. This is not a life threatening condition, but it is very painful. And the pain wont go away by itself. It is necessary for you to visit a surgeon who will put this on its place - it will ease the pain. After that, you need to make inflammation (as it is most probably inflamed) go away and then you may need surgery.
The stomach pain is most likely caused by something else as hemorrhoids cause pain only around the anus.
Depending of the localization of the stomach pain it can be peptic ulcer (upper middle abdomen, the pain appears after a meal), gallstones (right upper abdomen, pain radiates to the back, appears after a meal),
urinary tract infection (the pain can be present on left or right side, can radiate to the back or groin,
frequent urination and burning after urinating appears),
diverticulitis (left middle and lower abdomen, associated with severe constipations),
appendicitis (right lower abdomen), pregnancy, ovarian cyst,
ovarian inflammation and many others.
It is advisable for you to have full blood work, urine analysis, abdominal ultrasound.
Hope this will help.
Regards.