#include <bits/stdc++.h>
using namespace std;
void f(int n, string& a, string& b) {
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] != b[i]) {
      cnt += 3;
    }
  }
  cout << cnt << " ";
  for (int i = n - 1; i >= 0; i--) {
    if (a[i] == b[i]) {
      continue;
    }
    cout << i + 1 << " " << 1 << " " << i + 1 << " ";
  }
  cout << "\n";
}
int main() {
  int t;
  cin >> t;
  for (int j = 0; j < t; j++) {
    int n;
    cin >> n;
    string a;
    string b;
    cin >> a >> b;
    f(n, a, b);
  }
  return 0;
}
