#include <bits/stdc++.h>
using namespace std;
void chr(string &s, int pr) {
  if (pr % 2 == 1) {
    if (s[pr / 2] == '0') {
      s[pr / 2] = '1';
    } else {
      s[pr / 2] = '0';
    }
  }
  for (int i = 0; i < pr / 2; i++) {
    if (s[i] == s[pr - 1 - i]) {
      if (s[i] == '0') {
        s[i] = '1';
        s[pr - 1 - i] = '1';
      } else {
        s[i] = '0';
        s[pr - 1 - i] = '0';
      }
    }
  }
}
int main() {
  int t;
  cin >> t;
  vector<vector<int>> p;
  p.resize(t);
  for (int j = 0; j < t; j++) {
    int n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    for (int i = n - 1; i >= 0; i--) {
      if (a[i] != b[i]) {
        if (a[0] != b[i]) {
          p[j].push_back(i + 1);
          chr(a, i + 1);
        } else {
          p[j].push_back(1);
          chr(a, 1);
          p[j].push_back(i + 1);
          chr(a, i + 1);
        }
      }
    }
  }
  for (int i = 0; i < t; i++) {
    cout << p[i].size() << " ";
    for (int j = 0; j < p[i].size(); j++) {
      cout << p[i][j] << " ";
    }
    cout << endl;
  }
}
