#include <bits/stdc++.h>
using namespace std;
int st1[1001], st2[1001];
int n;
void flip(int i) {
  int j;
  for (j = 1; j <= i; j++) st1[j] = st1[j] ^ 1;
  j = 1;
  while (j < i) {
    swap(st1[i], st1[j]);
    j++;
    i--;
  }
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    cin >> n;
    char ch;
    for (int i = 1; i <= n; i++) {
      cin >> ch;
      st1[i] = ch - '0';
    }
    for (int i = 1; i <= n; i++) {
      cin >> ch;
      st2[i] = ch - '0';
    }
    vector<int> v;
    for (int i = n; i >= 2; i--) {
      if (st1[i] != st2[i]) {
        if (st2[i] == st1[1]) {
          st1[1] = st1[1] ^ 1;
          v.push_back(1);
        }
        v.push_back(i);
        flip(i);
      }
    }
    if (st1[1] != st2[1]) v.push_back(1);
    cout << v.size() << " ";
    for (int i = 0; i < v.size(); i++) cout << v[i] << " ";
    cout << endl;
  }
}
