MADRID, Spain (AP) _ First lady Nancy Reagan, who says she has Spanish blood, danced the flamenco Tuesday during the presidential visit to Spain.

Mrs. Reagan's one-minute performance of the traditional gypsy-style Spanish dance was praised by Queen Sofia and loudly applauded by flamenco students from the Royal School of Dance and Dramatic Arts.

''I think she had great rhythm - fantastic,'' said the queen.

During a visit to the Prado Museum, Mrs. Reagan told curator Alfonso Perez Sanchez that her great-great-grandmother married a Spaniard.

''On that side of the family they were all blue-eyed and blonde-haired and then I came along and everyone wondered where I came from,'' she said.

At a lunch later, Mrs. Reagan said of her flamenco fling: ''Theirs was good - mine was terrible.''

In 1972, when the president was California's governor and the Reagans visited Spain as special emissaries of then-President Richard M. Nixon, both were invited onto the stage of a Madrid flamenco show, where Reagan danced a few steps with the main woman dancer of the troupe.

Mrs. Reagan stood in the back with the men, clapping her hands to the guitar music.

On Tuesday, Mrs. Reagan watched a performance by flamenco students between ages nine and 17 at the Royal Theater.

Seventeen-year-old Oscar Jimenez, the only male in the show, invited Mrs. Reagan to dance and she accepted.

The First Lady, who was wearing a rust and brown two-piece dress, quickly picked up the steps of the ''sevillanas,'' a type of flamenco dancing, and was working on the raised arm movements when she decided to call it quits.

''You're quite a flamenco dancer,'' a reporter told her later.

''Oh no, no. I think you have to start very young,'' she replied.

''Was it a surprise?'' the reporter asked.

''It certainly was,'' the First Lady said.

Jennefer Hirschberg, her press secretary, said later that the White House had been asked whether it would be okay to ask Mrs. Reagan to dance, but Mrs. Reagan did not make a decision beforehand. ''We were going to let her play it by ear,'' she said.

As the party left the National Theater, several dozen people outside applauded and shouted ''Viva Reagan,'' nearly drowning out a lone protester shouting ''Reagan get out.''

At the Prado, Mrs. Reagan and the queen spent more than half an hour looking at masterpieces by artists El Greco, Velazquez and Goya.

The First Lady said later her favorite painting was a small Velazquez done in impressionist style which the Spanish news agency identified as ''Villa Medici.''

Mrs. Reagan was guest of honor at a luncheon hosted by the queen at Madrid's oldest restaurant, the Sobrino de Botin, a favorite haunt of Ernest Hemingway. As they arrived, several hundred people shouted ''Viva,'' again almost drowning out a few anti-Reagan protesters.