You need to store something about the posts you want to check on an exclude. For example the post ID of the main post.
// before your custom query
$main_post_id = $post->ID;
foreach ($mainbrandquery as $m) {
if ($m->ID == $main_post_id) {
// skip this one
continue;
}
// nested loop
foreach ($subproducts as $s) {
if ($m->ID == $s->ID || $s->ID == $main_post_id) {
// skip this one
continue;
}
}
}