#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int a[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  a[0] = 1;
  while (t--) {
    int n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    vector<int> v;
    int cnt = 0;
    for (int i = n - 1; i >= 1; i--) {
      if (a[i] != b[i]) {
        cnt++;
        if (a[0] == b[i]) {
          v.push_back(0);
        }
        v.push_back(i);
        int j1 = 0, j2 = i;
        while (j1 <= j2) {
          swap(a[j1], a[j2]);
          if (a[j1] == '0')
            a[j1] = '1';
          else
            a[j1] = '0';
          if (j1 != j2) {
            if (a[j2] == '0')
              a[j2] = '1';
            else
              a[j2] = '0';
          }
          j1++;
          j2--;
        }
      }
    }
    if (a[0] != b[0]) {
      v.push_back(0);
    }
    cout << v.size() << " ";
    for (int x : v) cout << x + 1 << " ";
    cout << "\n";
    ;
  }
  return 0;
}
