Matrix with an entries field and need to grab category title Any help would be greatly appreciated! I hope I explained my situation in enough detail to get the help that is needed.

Currently I have two channels that need to share information. This is going from one channel to an other.  

Channel One is called Resellers
This information needs to be feed into my other channel called Products.
Reseller contains info about various resellers, places to purchase a product. 
In this channel I have a field for Category. The category is actually a Country name. The rest of the fields are plain text.  

Channel 2 is called Products 
Products has various fields but I am interested in doing is pulling in info from Resellers and displaying it. I am able to pull in everything from Resellers except for the Category name.

In Products I have a matrix field that contains an entry field and a plain text field. 
The entry field pulls in the information about each reseller. 
The plain text field allows me to override a field from Reseller to display per product information. I got this part working without an issue.  

What I am trying to create is the following structure:
Country name then under the country list out each reseller alphabetically.
You will see Country Name A, A means nothing it just shows alphabetical listing. 


Country Name A 


Reseller A 
Reseller T

Country Name C


Reseller D
Reseller H
Reseller R
Reseller T



Below I have listed out my field handle names that are relevant to this issue.

From Resellers


rdCountry - field where category is selected from


I am able to pull in all other fields easily that are part of Resellers.

From Products


Matrix field - chooseResellers


Entries field - chooseReseller
Plain text field - customProductLink



Again I am able to display each reseller just fine. What I am having issues with is pulling in the Category/Country name. Once I pull in the country name I might need help with setting up my loop to display everything.

Thanks for your time and help, it is greatly appreciated! 

EDIT:
So the below code seems to solve my issue listed above. Now I just gotta loop through everything correctly.

{% for entry in craft.entries.slug(entrySlug).find() %}
    {% for block in entry.chooseResellers %}
        {% for reseller in block.chooseReseller %}
            &lt;h3&gt;{{ reseller.rdCountry.first() }}&lt;/h3&gt;
        {% endfor %}
    {% endfor %}{# /matrix #}
{% endfor %}{# /for product #}


EDIT TWO - the code solves part of the problem but I do not think will allow me to loop through everything as I was expecting. Help is appreciated!
To achieve structure:


Country Name A


Reseller C

Country Name C


Reseller B
Reseller D



With configuration:

Category Countries

Channel Resellers:


rdCountry (Country Categories) field


Channel Products:


chooseResellers (Matrix) field


block


chooseReseller (Reseller Entries) field




You gonna need code like this:

{% for entry in craft.entries.slug(entrySlug).find() %}
    {% set countries = {} %}
    {% for block in entry.chooseResellers %}
        {% for reseller in block.chooseReseller.with(['rdCountry']) %}
            {% set countryName = reseller.rdCountry[0].title %}

            {% if countries[countryName] is defined %}
                {% set temp = countries[countryName] | merge([reseller]) %}
                {% set countries = countries | merge({(countryName): temp}) %}
            {% else %}
                {% set countries = countries | merge({(countryName): [reseller]}) %}
            {% endif %}

        {% endfor %}
    {% endfor %} 

    {% for countryName, resellers in countries %}
        &lt;h3&gt;{{ countryName }}&lt;/h3&gt;
        {% for reseller in resellers %}
            &lt;p&gt;{{ reseller.title }}&lt;/p&gt;
        {% endfor %}
    {% endfor %}
{% endfor %}




Because of the current section/field/relation configuration we need to use countries temporary array to store Country => Reseller structure. 

.with(['rdCountry']) is what you call eager loading. It allows you to reduce sql queries, speed up the whole process. With eager loaded entries field you replace find() with index number.

countries looks like this at the end:

{  
   "Country Name A":[  
      {  
         "title":"Reseller C"
      }
   ],
   "Country Name C":[  
      {  
         "title":"Reseller B"
      },
      {  
         "title":"Reseller D"
      }
   ]
}