We build a Trie data structure to count how many words start with a given prefix. Each node in the Trie represents a character and stores how many words pass through it as a prefix. When inserting words like 'apple', 'app', and 'ape', we create nodes for characters if they don't exist and increment counts at each node. For example, after inserting 'apple', the nodes for 'a', 'p', 'p', 'l', 'e' each have count 1. Inserting 'app' increments counts on 'a', 'p', 'p' to 2. Inserting 'ape' increments counts on 'a', 'p', and creates a new 'e' node under 'p'. When querying a prefix like 'ap', we traverse nodes for 'a' and 'p' and return the count stored at 'p', which is 3, meaning 3 words start with 'ap'. If the prefix is not found, like 'bat', we return 0. This method efficiently counts words sharing prefixes by storing counts during insertion.