#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n;
  cin >> n;
  string s, s1;
  cin >> s >> s1;
  deque<char> q, q1;
  for (auto it : s) {
    q.push_back(it);
  }
  for (auto it : s1) {
    q1.push_back(it);
  }
  vector<long long int> ans;
  int check = 0;
  long long int curr = n;
  while (!q1.empty()) {
    if (check == 0) {
      if (q.back() == q1.back()) {
        q.pop_back();
        q1.pop_back();
      } else {
        if (q.front() != q1.back()) {
          ans.push_back(curr);
          check = 1;
          q.pop_front();
          q1.pop_back();
        } else {
          check = 1;
          ans.push_back(1);
          ans.push_back(curr);
          q.pop_front();
          q1.pop_back();
        }
      }
    } else {
      if (q.front() != q1.back()) {
        q.pop_front();
        q1.pop_back();
      } else {
        if (q.back() == q1.back()) {
          ans.push_back(curr);
          check = 0;
          q.pop_back();
          q1.pop_back();
        } else {
          check = 0;
          ans.push_back(1);
          ans.push_back(curr);
          q.pop_back();
          q1.pop_back();
        }
      }
    }
    curr--;
  }
  cout << ans.size() << " ";
  for (auto it : ans) {
    cout << it << " ";
  }
  cout << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t = 1;
  cin >> t;
  for (long long int i = 0; i < t; i++) {
    solve();
  }
  return 0;
}
