#include <bits/stdc++.h>
using namespace std;
int n;
string a, b;
void perform(int len) {
  for (int i = 0; i < len / 2; ++i) {
    if (a[i] == a[len - 1 - i]) {
      a[i] = '0' + '1' - a[i];
      a[len - 1 - i] = '0' + '1' - a[len - 1 - i];
    }
  }
  if (len & 1) a[len / 2] = '0' + '1' - a[len / 2];
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> a >> b;
    int k = 0;
    vector<int> ops;
    for (int i = n - 1; i >= 0; --i) {
      if (a[i] != a[0]) perform(1), ++k, ops.push_back(1);
      if (a[i] != b[i]) perform(i + 1), ++k, ops.push_back(i + 1);
    }
    cout << k << ' ';
    for (int x : ops) cout << x << ' ';
    cout << endl;
  }
  return 0;
}
