FORT RILEY, Kan. (AP) _ The remains of three Japanese prisoners from World War II have been exhumed from their graves in a private ceremony at the Fort Riley Army post and will be returned this week to their families in Japan.

The remains of the crewmen from the submarine Ro were cremated in Topeka after Monday's ceremony, attended by a small crowd of American soldiers and Japanese officials.

''We all know that in countries all over the world that servicemen paid for a legacy of freedom with their blood,'' said Col. Yoshimasa Miyamoto, a Japanese liason officer at Fort Leavenworth. ''We stand here today as soldiers once in opposition, now unified as allies.''

''This disinterrment will finally mark the end of the war for these families,'' Miyamoto said.

Hideo Numata, Japanese consul general in Kansas City, Mo., read a letter from the families of the men thanking the Army and the United States for keeping up the graves.

The three crewmen were held at a POW camp in Colorado after their capture, and official records show they died Oct. 29, 1944, in a Denver hospital. They were buried at Camp Carson, Colo., but the remains were transferred to Fort Riley in 1946 as part of a consolidation program.

Army officials said 64 German POWs and 11 Italian POWs are buried at the base cemetery.

It is not known where or how the three Japanese Navy men were captured or what caused their deaths, Numata said. He said he knew of no other Japanese POWs buried in the United States.

A member of the Self-Defense Forces of Japan who was studying at Fort Leavenworth discovered the graves in 1963 while on a tour of Fort Riley. He gave photographs of the headstones to the Japanese Ministry of Health and Welfare.

With information supplied by the U.S. Department of the Army, the ministry was able to eventually identify the dead men's families and confirm their desire to have the remains returned to Japan.