#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    vector<long long> v;
    for (long long i = 0; i < n; i++) {
      if (a[0] == b[n - i - 1]) {
        v.push_back(1);
        if (a[0] == '0')
          a[0] = '1';
        else
          a[0] = '0';
      }
      v.push_back(n - i);
      string s = "";
      for (long long j = 0; j < n - i; j++) {
        if (a[j] == '0')
          s += '1';
        else
          s += '0';
      }
      reverse(s.begin(), s.end());
      for (long long j = 0; j < s.length(); j++) a[j] = s[j];
    }
    cout << v.size() << " ";
    for (auto x : v) cout << x << " ";
    cout << '\n';
  }
}
