#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    string aa, bb;
    cin >> aa >> bb;
    long long int a[n], b[n];
    for (long long int i = 0; i < n; i++) {
      a[i] = (aa[i] == '1') ? 1 : 0;
      b[i] = (bb[i] == '1') ? 1 : 0;
    }
    vector<long long int> v;
    long long int rev = 0;
    long long int len = n;
    long long int fb = a[0];
    for (long long int i = n - 1; i >= 0; i--) {
      if (a[0] != b[i]) {
        string s;
        for (long long int j = 0; j <= i; j++) s += (a[j] == 1) ? '0' : '1';
        reverse(s.begin(), s.end());
        for (long long int j = 0; j <= i; j++) {
          a[j] = (s[j] == '1') ? 1 : 0;
        }
        v.push_back(len);
      } else {
        v.push_back(1);
        a[0] = !a[0];
        string s;
        for (long long int j = 0; j <= i; j++) s += (a[j] == 1) ? '0' : '1';
        reverse(s.begin(), s.end());
        for (long long int j = 0; j <= i; j++) {
          a[j] = (s[j] == '1') ? 1 : 0;
        }
        v.push_back(len);
      }
      len--;
    }
    for (long long int i = 0; i < n; i++) {
      if (a[i] != b[i]) cout << "Wrong";
    }
    cout << v.size() << " ";
    for (long long int i = 0; i < v.size(); i++) {
      cout << v[i] << " ";
    }
    cout << "\n";
  }
}
