void solve() {
int n, m, k; cin >> n >> m >> k;
vector<int> a(n+1);
for(int i = 1;i <= n; i++) cin >> a[i];
vector<int> b(m+1);
for(int i = 1;i <= m; i++) cin >> b[i];
vector<bool> v(n+1);
priority_queue<pair<int, int>> q;
//开船的人之间怎么才能不会冲突
if(n == 1 && m == 1){
cout << "YES\n";
cout << 1 << "\n";
cout << "1 1\n";
return ;
}
int x = 0, y = 0;
for(int i = 1;i <= m; i++) x = b[i], y = b[i];
for(int i = 1;i <= m; i++) v[b[i]] = false;
for(int i = 1;i <= m; i++){
v[b[i]] = true;
for(int j = 1;j <= m; j++){
if(v[b[j]] || j == i) continue;
if(a[b[i]] % a[b[j]] == k || a[b[j]] % a[b[i]] == k){
continue;
}else{
v[b[j]] = true;
x = b[i], y = b[j];
break;
}
}
}
for(int i = 1;i <= n; i++) v[i] = false;
queue<pair<int, int>> p;
p.push({x, y});
p.push({x, x});
v[x] = true;
v[y] = true;
map<int, int> mp;
for(int i = 1;i <= m; i++){
if(v[b[i]]) continue;
if(a[b[i]] % a[x] == k || a[x] % a[b[i]] == k){
continue;
}else{
v[b[i]] = true;
p.push({x, b[i]});
p.push({x, x});
}
}
for(int i = 1;i <= m; i++){
if(!v[b[i]]){
for(int j = 1;j <= n; j++){
if(a[b[i]] % a[j] == k || a[j] % a[b[i]] == k){
continue;
}else{
v[b[i]] = true;
v[j] = true;
p.push({b[i], j});
p.push({y, y});
p.push({x, y});
p.push({x, x});
break;
}
}
}
}
//先把不会开船的全送走
for(int i = 1;i <= m; i++){
for(int j = 1;j <= n; j++){
if(v[j]) continue;
if(a[b[i]] % a[j] == k || a[j] % a[b[i]] == k){
continue;
}else{
v[j] = true;
q.push({b[i], j});
}
}
}
for(int i = 1;i <= n; i++){
if(!v[i]){
cout << "NO\n";
return ;
}
}
p.push({x, x});
while(!q.empty()){
auto [xx, yy] = q.top();
p.push({xx, xx});
p.push({xx, yy});
q.pop();
}
int len = p.size();
cout << "YES\n";
cout << len << "\n";
while(!p.empty()){
auto [xx, yy] = p.front();
cout << xx << " " << yy << "\n";
p.pop();
}
}