#include <bits/stdc++.h>
using namespace std;
long long INF = 1e9 + 7;
int MOD = 998244353;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    vector<long long> ans;
    for (int i = n - 1; i >= 0; i--) {
      if (a[i] != b[i]) {
        if (a[0] == a[i]) {
          ans.push_back(i + 1);
          reverse(a.begin(), a.begin() + i + 1);
          for (int j = 0; j <= i; j++)
            if (a[j] == '1')
              a[j] = '0';
            else
              a[j] = '1';
        } else {
          ans.push_back(1);
          ans.push_back(i + 1);
          reverse(a.begin(), a.begin() + i + 1);
          for (int j = 0; j <= i - 1; j++)
            if (a[j] == '1')
              a[j] = '0';
            else
              a[j] = '1';
        }
      }
    }
    cout << ans.size() << ' ';
    for (int num : ans) cout << num << ' ';
    cout << '\n';
  }
}
