#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    string a, b;
    cin >> n >> a >> b;
    vector<int> ans;
    for (int i = n - 1; i > 0; i--) {
      if (a[i] != b[i]) {
        if (a[0] == b[i]) {
          ans.push_back(1);
          a[0] = (a[0] == '1' ? '0' : '1');
        }
        ans.push_back(i + 1);
        for (int j = 0; j <= i; j++) a[j] = (a[j] == '1' ? '0' : '1');
        for (int j1 = 0, j2 = i; j1 < j2; j1++, j2--) swap(a[j1], a[j2]);
      }
    }
    if (a[0] != b[0]) ans.push_back(1);
    cout << ans.size() << " ";
    for (int u : ans) cout << u << " ";
    cout << "\n";
  }
}
