#include <bits/stdc++.h>
using namespace std;
string a, b;
int cntl, cntr;
int flag;
int cnt;
void next() {
  if (flag == 1) {
    cntl++;
    cnt = cntr;
  } else {
    cntr--;
    cnt = cntl;
  }
  flag = 1 - flag;
}
vector<int> v;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T;
  cin >> T;
  while (T--) {
    v.clear();
    int n;
    cin >> n;
    cin >> a >> b;
    flag = 1;
    cnt = 0;
    cntl = 0;
    cntr = a.size() - 1;
    for (int i = a.size() - 1; i >= 0; i--) {
      if (i == 0) {
        if (a[cnt] != b[i] && flag == 1 || a[cnt] == b[i] && flag == 0)
          v.push_back(1);
        break;
      }
      if (a[cnt] == b[i] && flag == 1 || a[cnt] != b[i] && flag == 0) {
        v.push_back(1);
        v.push_back(i + 1);
      } else
        v.push_back(i + 1);
      next();
    }
    printf("%d ", v.size());
    for (int i = 0; i < v.size(); i++) printf("%d ", v[i]);
    putchar('\n');
  }
  return 0;
}
