#include <bits/stdc++.h>
using namespace std;
int n;
string a, b;
vector<int> V;
void calc(int l, int r, int pref) {
  if (pref == 0) return;
  if (pref == 1) {
    if (a[l] == b[0]) {
      return;
    }
    V.push_back(1);
    return;
  }
  if (a[r] == b[pref - 1]) {
    calc(l, r - 1, pref - 1);
    return;
  }
  if (a[l] == b[pref - 1] && b[pref - 2] == b[pref - 1]) {
    V.push_back(1);
    V.push_back(pref);
    V.push_back(1);
    V.push_back(pref - 1);
    calc(l + 1, r - 1, pref - 2);
    return;
  }
  if (a[l] == b[pref - 1] && b[pref - 2] != b[pref - 1]) {
    V.push_back(1);
    V.push_back(pref);
    V.push_back(pref - 1);
    calc(l + 1, r - 1, pref - 2);
    return;
  }
  if (a[l] != b[pref - 1] && b[pref - 2] == b[pref - 1]) {
    V.push_back(pref);
    V.push_back(1);
    V.push_back(pref - 1);
    calc(l + 1, r - 1, pref - 2);
    return;
  }
  if (a[l] != b[pref - 1] && b[pref - 2] != b[pref - 1]) {
    V.push_back(pref);
    V.push_back(pref - 1);
    calc(l + 1, r - 1, pref - 2);
    return;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    cin >> n;
    cin >> a >> b;
    calc(0, a.size() - 1, b.size());
    cout << V.size() << endl;
    for (auto a : V) cout << a << " ";
    cout << endl;
    V.clear();
  }
  return 0;
}
