Habitat Quality Determines Dispersal Decisions and Fitness in a Beetle – Fungus Mutualism

Delayed dispersal of sexually mature offspring is a fundamental component of cooperative breeding. In ambrosia beetles, female offspring temporarily remain in their natal nest and refrain from reproduction, instead investing in alloparental care. Previous work has demonstrated a link between helping behaviour and the increased need for pathogen defence, arising from their close association with fungal cultivars. In the ambrosia beetle Xyleborinus saxesenii, mature female offspring can effectively fight pathogen infections and manage the microbial composition within the nest by adjusting the frequency of different hygienic and nest maintenance behaviours. This suggests a potential to respond flexibly to the ecology of their nest, which calls for a better understanding of the connection between behaviour and the microbial community thriving within their nests. Here, we studied the significance of the mutualistic fungus garden composition for the beetles’ nest ecology and fitness by experimentally varying substrate quality. We found that the vertically transmitted ambrosia fungus garden is composed of at least two fungus mutualist species and a wide variety of other microbes varying in their relative abundance. This is strongly affected by the moisture content of the substrate, which in nature depends on the age and type of wood. We found that the mutualist fungi complement each other in terms of dryness-resistance, allowing the beetles to utilise a broad range of substrates over prolonged time during which the wood gradually desiccates. Under suboptimal humidity conditions, the interaction between host and multiple fungus species has important ramifications for the behaviour of philopatric helpers, including their alloparental investment, sibling cannibalism and the timing of dispersal. Rearing five generations of beetles consecutively in dry substrate resulted in transgenerational effects on philopatry and alloparental care, probably mediated through the dominance of a particular fungus species that was driven by the experimental habitat condition. Interestingly, the nests of these selection lines produced much more offspring after five generations than any first-generation nest, which may have reflected increased egg laying by non-dispersing daughters. Our study highlights the importance of considering the interactions between the microbial community and their insect hosts for understanding social evolution in cooperatively breeding beetles.

Delayed dispersal of sexually mature offspring is a fundamental component of cooperative breeding. In ambrosia beetles, female offspring temporarily remain in their natal nest and refrain from reproduction, instead investing in alloparental care. Previous work has demonstrated a link between helping behaviour and the increased need for pathogen defence, arising from their close association with fungal cultivars. In the ambrosia beetle Xyleborinus saxesenii, mature female offspring can effectively fight pathogen infections and manage the microbial composition within the nest by adjusting the frequency of different hygienic and nest maintenance behaviours. This suggests a potential to respond flexibly to the ecology of their nest, which calls for a better understanding of the connection between behaviour and the microbial community thriving within their nests. Here, we studied the significance of the mutualistic fungus garden composition for the beetles' nest ecology and fitness by experimentally varying substrate quality. We found that the vertically transmitted ambrosia fungus garden is composed of at least two fungus mutualist species and a wide variety of other microbes varying in their relative abundance. This is strongly affected by the moisture content of the substrate, which in nature depends on the age and type of wood. We found that the mutualist fungi complement each other in terms of dryness-resistance, allowing the beetles to utilise a broad range of substrates over prolonged time during which the wood gradually desiccates. Under suboptimal humidity conditions, the interaction between host and multiple fungus species has important ramifications for the behaviour of philopatric helpers, including their alloparental investment, sibling cannibalism and the timing of dispersal. Rearing five generations of beetles consecutively in dry substrate resulted in transgenerational effects on philopatry and alloparental care, probably mediated through the dominance of a particular fungus species that was driven by the experimental habitat condition. Interestingly, the nests of these selection lines produced much more offspring after five generations than any first-generation nest, which may have reflected increased egg laying by non-dispersing daughters. Our study highlights the importance of considering the interactions between the microbial community and their insect hosts for understanding social evolution in cooperatively breeding beetles.
Keywords: social evolution, habitat quality, cooperation, insect-fungus mutualism, ambrosia beetles, cooperative breeding, Xyleborinus saxesenii, dispersal INTRODUCTION Cooperative breeding is characterized by alloparental care (i.e., brood care shown by non-parents), which evolved independently in many taxonomic groups including spiders, insects, fish, birds and mammals (Skutch, 1961;Taborsky, 1994;Choe and Crespi, 1997;Koenig and Dickinson, 2016;Rubenstein and Abbot, 2017). An alloparent's propensity to help caring for the offspring of others is often attributed to inclusive fitness benefits (Hamilton, 1964;Bourke, 2011) and correlated payoffs (Taborsky et al., 2016). Adverse conditions like harsh environments, high predation risk and habitat saturation may cause dispersal delays, which sets the stage for the evolution of alloparental brood care by philopatric individuals (Stacey, 1979;Koenig et al., 1992;Heg et al., 2004;Mullon et al., 2018). In contrast to these environmental constraints, the potential significance of interspecific relations for the evolution of philopatry, alloparental care, task partitioning and social behaviour in cooperative breeders has received little attention. This is an important gap especially concerning invertebrates that are strongly affected by relationships with microbes such as fungi and bacteria (Hart et al., 2002;Mueller et al., 2005;Biedermann and Rohlfs, 2017).
Microbes can have various adverse effects on insects that may be mitigated by brood care. For instance, many social insects have evolved nesting behaviours where constant grooming of the offspring lowers the risk of infection and spread of pathogens (Ayasse and Paxton, 2002). Such nest-wide social pathogen defence behaviours have been conceptually framed as "social immunity traits" (Cremer et al., 2007). There is growing evidence that the evolution of social immunity traits goes hand in hand with the evolution of complex insect sociality, since they have been observed in a range of insects showing different degrees of parental and alloparental brood care, including eusocial taxa as well as burying beetles with biparental brood care and cooperatively breeding ambrosia beetles (Cotter et al., 2010;Meunier, 2015;Van Meyel et al., 2018;Nuotclà et al., 2019).
Social immunity in cooperatively breeding insects is apparently linked to their frequent exposure to microorganisms that compete for food or can have pathogenic effects, depending on the natural feeding ecology of the species. Burying beetles, for example, lay their eggs on buried carcasses of small vertebrates that are kept from rotting with the help of microorganisms (Shukla et al., 2018). Ambrosia beetles, on the other hand, dig their nests into the heartwood of trees, where they maintain a wood-colonizing garden of fungal mutualists as their sole food source. In these taxa, a central component of alloparental brood care consists of constant grooming of both the offspring and the food source. This keeps the offspring free from microbial growth  and it may be instrumental for the maintenance of a healthy mutualist community by selective removal of harmful microbes and spreading of beneficial species (Shukla et al., 2018;Nuotclà et al., 2019). Such intensive care for microbial mutualists is typically associated with highly social and fungiculturing attine ants and microtermitine termites, where the association with fungal crop "gardens" has led to extreme behavioural and physiological adaptations (Hölldobler and Wilson, 2009;Korb, 2010;Vesala et al., 2019;Biedermann and Vega, 2020). In some of these eusocial insects, part of the workers are even physically optimized for certain tasks associated with tending the fungal crop (Hart et al., 2002).
The importance of mutualistic microbes for the evolution of complex sociality is poorly understood. The association with mutualistic microbes may have facilitated the evolution of a social lifestyle in insects by providing them with a virtually endless food source, or under certain conditions sociality might be a prerequisite for maintaining a highly demanding fungiculture in the first place. As transitionary forms of sociality are rare in the eusocial insect taxa, the study of microbial influence on social evolution should focus on cooperatively breeding species relying on microbes for food or on other services. Recent studies suggest that under these circumstances, cooperation among siblings is necessary to compensate for increased pathogen pressure and a potential loss of parental care, if parents disappear (Nuotclà et al., 2019;Rebar et al., 2020).
Ambrosia beetles are a highly suitable model system to explore the relationship between insect hosts and their microbial mutualists since they independently evolved fungiculture at least 12 times (Kirkendall et al., 2015;Johnson et al., 2018), and different levels of social complexity can be found amongst the more than 3,500 known species. Brood care ranges from simple uniparental care to alloparental care and complex division of labour Kirkendall et al., 2015). Compared to other wood-dwelling species that either consume nutrient rich phloem or wood tissue directly, fungus farming ambrosia beetle offspring might be much more dependent on brood care. In most species, the mutualistic fungus garden propagules are vertically transmitted by dispersing females and the garden needs to be first established before the female can begin to lay its eggs. Tunnels of wood boring insects offer ideal access points to a whole range of wood dwelling microbes, allowing them to penetrate trough the bark deeper into the heartwood of a tree (Ulyshen, 2016;Skelton et al., 2019). Some microbes may be in direct competition with the beetles' fungal mutualists and may even lead to a premature collapse of the nest (Nuotclà et al., 2019). Additionally, feeding on a fungus garden renders ambrosia beetle offspring less mobile compared to other wood dwelling species that constantly eat their way through fresh wood. This may render ambrosia beetles more vulnerable to pathogens entering the nest via the maternal entrance hole. Active microbial management may therefore be important not only in the establishment phase of a nest, but also throughout its entire lifetime. For instance, previous work on Xyleborinus saxesenii has demonstrated that these beetles show strong behavioural changes when the nest is challenged with a high pathogen load, leading to an effective social immune response and increased alloparental investment by daughters. This also caused delayed dispersal, apparently to fight the infection (Nuotclà et al., 2019). The present study expands on this work by shifting the focus from harmful to beneficial microbes in order to explore their potential role as drivers of dispersal decisions, parental care and social evolution. Newly developed methods for efficient lab rearing of the ambrosia beetles (Norris and Chu, 1985;Peer and Taborsky, 2004;Biedermann et al., 2009) and molecular tools for analysing the microbial associates (Skelton et al., 2018(Skelton et al., , 2019 allow for an integrated approach to study microbe-driven social behaviour. Our study system, Xyleborinus saxesenii dwells in relatively freshly dead wood of various tree species (Fischer, 1954). This breeding substrate may vary in humidity, depending on the degree of degradation as dead wood dries out constantly. The ephemerality of this dead wood habitat has been hypothesized to be a major hurdle for the evolution of complex sociality in ambrosia beetles, since it restricts the potential nest persistence and thus limits the overlap of multiple offspring generations (Kirkendall et al., 1997). In fact, the only candidate species where complex sociality beyond alloparental care has been assumed so far is also one of the very few species breeding exclusively in living trees, which allows for much longer lasting nests (Kent and Simpson, 1992;Smith et al., 2018). Besides the immediate limiting factor of diminishing nutrients in a dead tree (Ulyshen, 2016), the main limitation to nest longevity probably arises from the requirements of the ambrosia fungus garden, which was shown to be very sensitive to the humidity of the wood substrate. The chances that the beetles successfully establish a fungus garden is reduced when moisture levels are not within a certain range (cf. Hosking, 1973;Zimmermann and Butin, 1973;Biedermann et al., 2009;Ulyshen, 2016;personal observations). Since the beetles fully rely on these fungi for food, the initial quality of the substrate and the way it changes over time probably has a significant impact on fungus garden productivity, nest longevity and thus ultimately on the beetles' fitness. Behavioural strategies to slow down the drying of the wood, like plugging the entrance hole with a beetle's body or with faeces and frass, have been discussed but it is unclear to which degree the beetles or the fungus might be able to influence resource stability of the host tree (Kirkendall et al., 1997).
Under optimal humidity conditions, X. saxesenii shows a heterogeneous age-class structure where mature and fertilized daughters delay their dispersal and serve as alloparents for their mother's brood (Biedermann et al., 2012). This cooperative breeding strategy allows for increased offspring numbers as compared to ambrosia beetle species with less complex social organisation (cf. Fischer, 1954;Taborsky, 2005, 2007;Kirkendall et al., 2015). Since suboptimal conditions lower the fungus productivity, when shifting moisture levels away from the optimum we would expect either a decrease in the speed of offspring development or a reduction in the overall number of offspring produced. Consequently, this might change the propensity of adult offspring to invest in alloparental care. In the present study we thus tested how the beetles and their microbial community respond to experimentally varied moisture levels, which might reveal evolved strategies to counteract the natural ephemeral quality of dead wood. In this regard, especially a close observation of adult daughter dispersal timing is of importance, since it correlates directly with their alloparental investment (Peer and Taborsky, 2007;. Substrate humidity may influence the whole microbial community in the nest, and special attention should be directed to the ambrosia fungus cultivars that constitute the main food source of both adults and larvae. X saxesenii gardens are comprised by the two species Raffaelea sulphurea and R. canadensis, which contrasts with most other ambrosia beetle species that are thought to be associated with only one species of mutualistic fungus. The reason for using more than one fungus species and how such associations can be maintained is hitherto unclear. In a first step, we explored how the alloparenting daughters respond to adverse conditions, since their propensity to cooperate might depend on nest performance. We hypothesized that under harsh conditions, mature daughters would increase their propensity to cooperate for boosting their immature sisters' survival chances. Alternatively, daughters might divert more energy to their own future reproduction by refraining from cooperation and dispersing early. The second possibility might also be favourable if the incentives to inherit such poor-quality nests are low. To test whether the mature offspring adjust their dispersal strategies according to the maternal nest conditions, we reared nests under three humidity regimes, providing either (1) the "normal" (optimal) condition yielding the most offspring as determined in previous experiments (Biedermann et al., 2009; own pilot data), (2) a "dry" condition simulating older wood and thinner, fast drying branches, or (3) a "humid" condition resembling very recently dead wood that is usually not preferred by the beetles in the field. We regularly counted how many nest members of different age classes were present in the gallery and analysed their behaviours. Since timing of dispersal strongly relates to the extent of cooperative investment of daughters, we recorded all dispersal events and collected dispersing females. The microbial composition they carried on their body was analysed to test for potential treatment effects. We expected that the diverging treatment conditions apply differential pressures on the microbiome, favouring the growth of different species in dry and humid conditions. The fungus composition carried by the females largely represents the microbiome species composition of maternal nests at the time of dispersal, and it correlates with the composition of species that can be found in the newly founded nest, i.e., in the next generation. This first experiment thus allows assessing the influence of habitat quality on social decision making, and it should provide insight into potential transgenerational effects of environmental challenges via differential selection pressures on the transmitted microbiome.
Living under suboptimal humidity regimes might not only change the relative microbial species composition within the nest but even cause a complete loss of certain humidity-sensitive microbial species. Since inbreeding ambrosia beetle species like X. saxesenii transmit their mutualists vertically from parental to daughter nests, a loss of certain microbial species would influence the species composition of future fungus gardens. Therefore, we hypothesized that sub-optimal habitat conditions can influence the fitness and cooperative strategies of a matriline over multiple generations.
To test this hypothesis, we exposed the beetles in a second experiment to "dry" conditions for five subsequent generations and observed the nest development patterns and timing of adult daughter dispersal. This served to assess (1) whether selection for a certain microbial composition would influence the beetle's dispersal strategies over generations, and (2) whether such a potential "acclimatisation" to dry conditions might be reversible when the beetles are subsequently exposed to optimal or "normal" nest growth conditions. If the microbial composition is changed during such multigenerational exposure to harsh conditions and cannot be easily reversed, we would expect a poorer performance of the fungal garden and a reduction in the beetles' fitness. This might change the incentives of mature daughters to either stay and cooperate or disperse and breed independently, which we determined by monitoring their dispersal timing.

Study Species
Xyleborinus saxesenii is an inbreeding species of polyphagous ambrosia beetle native to Eurasia. The closely related species Xylosandrus germanus exhibits an extremely low degree of outbreeding (Keller et al., 2011) and a significant outbreeding depression (Peer and Taborsky, 2005), which may be characteristic for many cooperatively breeding Xyleborini that exhibit similarly high inbreeding rates (but see Storer et al., 2017, reporting regular outbreeding in a sib-mating species). X. saxesenii is haplodiploid and shows a highly female biased sex ratio of about 1/20 (Peer and Taborsky, 2007). Females are capable of flight and emerge from their natal nest already mated, whereas the smaller males disperse on foot after their sisters have been fertilized, as they are incapable of flight (Peer and Taborsky, 2004;Biedermann, 2010). Such males may later try to outbreed by entering conspecific nests on the same log. A new nest is initiated after dispersal of a single female that first bores a tunnel with a single egg niche into a relatively fresh dead tree. She then inoculates it with wood digesting mutualistic fungi brought from her natal nest within a mycetangium (fungus storing organ; Francke-Grosmann, 1975). Once the fungus garden is well established, she lays a clutch of eggs and regularly cleans the eggs, which prevents them from being overgrown by the ambrosia fungi covering the walls of the tunnel. The gallery is then extended by the wood-chewing larvae into one or multiple large nest chambers. After pupation, mature offspring delay their dispersal and invest heavily in alloparental care by taking over nursing duties of their mother, which then serves mainly as a gatekeeper blocking the entrance tunnel with her body (Peer and Taborsky, 2007;Nuotclà et al., 2014). Larvae are also workers like adults, but in contrast to them they mainly contribute trough enlarging the nest by consuming the fungus veined wood and helping the adults to dispose of waste by forming frass pellets that are then shifted trough the nest. This exclusive larval behaviour is called "balling" and constitutes, together with nest enlargement, a rare example for division of labour in holometabolous insects .

Laboratory Beetle Rearing
All beetles used in this study dispersed from seventh generation laboratory nests. This lab population was originally started using females caught with ethanol baited traps in the Bremgarten-and Könizer Berg Forests near Bern, Switzerland. Each new nest was initiated by a single female that originally mated with a brother inside her natal nest. The founding female was first roughly surface sterilised by rinsing it for a few seconds with bleach ("Javel Water" containing <5% potassium hypochloride), followed by 96% ethanol and finally with sterilised deionised water, before placing it in a laboratory rearing tube containing artificial wood substrate. Substrate preparation followed a standard protocol (Nuotclà et al., 2019), except that we completely dried the beech wood sawdust at 60 • C before adding it to the mixture. The "normal" substrate contained 2.5 g sucrose, 2.5 g casein, 5 g starch, 2.5 g yeast extract, 0.63 g Wesson's salt mixture, 15 g agar, 100 g sawdust (beech), 5 ml peanut oil, 4 ml ethanol 97%, and 280 ml deionised water that were well mixed and then filled into clear polycarbonate tubes (Nalgene R centrifuge tubes, 16 ml, #3117-0160) before being capped and sterilized via autoclaving at 121 • C for 20 min. We added different amounts of deionised water according to the treatments; 40% of the original formula for the "dry" condition, 100% for the "normal" condition, and 150% for the "humid" condition. The "normal" substrate had been demonstrated to yield the highest offspring numbers in previous experiments (Biedermann et al., 2009) and was thus chosen as a baseline for all comparisons in the experiments. The humidity content of the "dry" substrate was chosen based on an unpublished pilot experiment that showed this to be the lowest limit where beetles produce viable offspring regularly enough for experimental use. Nests with as little as 20% of the "normal" water content did yield viable offspring in the lab, but the nest establishing success rate was too low to be practical for our experiments. The water content of the "humid" condition represents the upper end at which we could follow all steps of our standard protocol. Higher humidity contents would result in separation of the sawdust and agarose into two separate phases during autoclaving. Our treatments corresponded to a gravimetric water content of 82% for the dry, 204% for the "normal" and 307% for the "humid" condition (gravimetric water content: water weight divided by all other components times 100, expressed in percent). The water content of artificial sawdust-agar substrate needs to be higher compared to natural wood, because it loses its moisture faster than wood, even at high relative air humidity. Beechwood infested by ambrosia beetles under natural conditions has a mean gravimetric water content of 87-90% at the beginning of the season (end of April), which steadily declines to 43-60% until the end of the beetles' dispersal phase end of August (Zimmermann, 1973). Nest establishment success in natural conditions is expected to be around 20%, similarly to the closely related species X. germanus (Peer and Taborsky, 2007). Under laboratory conditions, the nest establishment success can vary between 5 and 50% (Biedermann et al., 2009;personal observations). Only nests with good visibility of the nest chambers were used in this study. Therefore, only nests where the tunnels and nest chambers were built near the tube wall were utilised while all others were discarded. All nests were stored in complete darkness in a ventilated climate chamber at controlled ambient conditions with 23 • C and 75% relative humidity.

Humidity Experiment
In the first experiment we manipulated the humidity content of our standard lab rearing substrate to change the conditions for microbial growth. We created three humidity regimes to approximate different wood substrates reflecting the total range of natural conditions. The "dry" substrate was meant to resemble older stages of dead wood or thin branches that have lost most of their humidity. The "normal" substrate represented the optimal conditions that were found to yield the highest nest establishment success (Biedermann et al., 2009; own pilot data). The "humid" substrate was meant to reflect freshly dead trees that still contain considerable sap flow. We established a high number of nests because of an expected low nest success rate and our confinement to tubes with good nest visibility. A pilot experiment showed that suboptimal humidity results in even lower nesting success compared to the "normal" condition ("dry"∼1/2 as successful and "humid"∼1/3 less successful than "normal"). We thus adjusted the number of initial tubes for each humidity category accordingly (start "dry": 150 tubes; "normal": 70 tubes; "humid":100 tubes). After successful establishment of a fungus garden and start of egg laying, the nests were monitored every 2-3 days. We noted the number of eggs, larvae, pupae, adult females and males and recorded their behaviours by scan sampling (cf. Nuotclà et al., 2019). From the moment a nest contained more than one adult individual, its tube cap was exchanged for a cap that allowed dispersing beetles to be captured, and the nest was turned so that the entrance tunnel pointed downward. This prevents dispersed beetles from crawling back into the nest, which helps obtaining precise information about dispersal timing. Dispersed beetles where either collected and snap-frozen on the dispersal day in a minus 80 • C freezer where they were stored until molecular analysis of the microbial community they carried, or they were used for subsequent laboratory rearing (see section "Selection Experiment, " below). After all beetles had dispersed from a nest, the substrate was removed from the tube and the maximal depth to which the beetles had dug their nest chamber was measured.
Some nests that successfully produced offspring collapsed. Thus, only nests that had at least two dispersing females were used for the final analysis to exclude unsuccessful nests. The success rate was 15% for dry, 19% for normal and 13% for humid nests. The final sample size for the humidity experiment was 23 nests with a total of 115 dispersing females for the "dry" treatment, 13 nests with a total of 136 dispersing females for the "normal" treatment, and 13 nests with a total of 84 dispersing females for the "humid" treatment.

Selection Experiment
In our second experiment we repeatedly reared dispersing females from the "dry" nest condition for five consecutive generations in "dry" substrate. In each generation we let 20 dispersing beetles initiate nests in 20 fresh tubes filled with "dry" substrate. After five generations exposed to this suboptimal substrate, we randomly assigned 100 dispersing beetles to start a new nest, half of them in "normal" and half of them in "dry" substrate. We monitored them similarly to the nests used for the humidity experiment, but without behavioural record and the microbial community assay. Again, we only analysed data for nests producing at least two dispersing females to exclude unsuccessful nests. The success rate here was 38% for dry and 14% for normal nests. For the final test of the selection experiment we obtained a sample size of 19 nests with a total of 974 dispersing females for the "dry" condition and 7 nests with a total of 255 dispersing females for the "normal" condition.

Collection of Samples for Microbial Analyses and DNA Extraction
We randomly selected five nests from each of the three treatments in the humidity experiment. From each of these nests we chose a beetle that dispersed on the very first day ("early disperser") and one beetle that dispersed on the very last day at which dispersal occurred ("late disperser"). The DNA extraction of these selected snap frozen beetles was conducted using the ZymoBIOMICS DNA Miniprep Kit (Zymo Research, Germany) in accordance with the manufacturer's instructions. Additionally, we included a treatment of the whole snap frozen beetles with ceramic beads in a bead beater, followed by another step with glass beads (0.1 and 0.5 mm) and swirling on a Vortex Genie 2 to break up cells at the beginning of the extraction. The isolated DNA samples were stored at −20 • C until further molecular analysis. Partial sequences for the 28S large subunit (LSU) ribosomal DNA (rDNA) were obtained from all samples for fungal identification using the newly designed dual-index primers LIC15R (originally from Miadlikowska et al., 2002) and nu-LSU-355-3' (originally from Döring et al., 2000), whereas sequences for the 16S rDNA for the identification of bacteria were obtained using the dualindex primers for the V4 region (Kozich et al., 2013). Our pairedend sequencing approach was performed on the Illumina MiSeq platform (see Supplementary Material for full protocol, primer design and details on bioinformatics processing).

Estimation of Day With Highest Individual Density
Based on previous lab studies with detailed individual counts over time Kajimura, 2002, 2009;Biedermann et al., 2012), we expected that the growth of larval and adult numbers (individual density) in a nest will follow a cubic regression in the form y = f (ax + bx ∧ 2 + cx ∧ 3 + d), with x representing the number of days since nest foundation, y representing the number of individuals, and the coefficients a, b, c and d describing the shape of the regression. Individual density is expected to initially increase as more individuals develop into that particular age class, reaching a maximum (point of highest individual density) before decreasing steadily while larvae develop into adults and adults disperse. The parameters a, b, c and d where determined for each nest and age class (larvae + pupae, adult females) using the function lme() in R (weighted least squares estimate). The derivative of f at the point y = 0 provided an estimate for the time point with the highest individual density of a certain age class for every nest (i.e., the two solutions for x in 0 = a + 2bx + cx ∧ 2 + d provide the two local extrema of the function, where x at the local maximum represents the day of highest individual density). This method was preferred over the use of the point in time at which the highest count of individuals was obtained, since it helps mitigating uncertainties caused by non-detected individuals over multiple observation days. This is necessary since perfect visibility into nest chambers rarely exists, even after selecting only the nests with good visibility for the experiment as described above. Post-hoc graphical evaluation for all individual nests confirmed that the individual counts for every age-class fitted well with the described regression, and that the calculated maxima of the function represented plausible estimates for the time point of a nest's highest individual density.

Analyses of Density, Dispersal, and Nest Depth
Significant deviation from homogeneity of variances (Levene test; for subadult offspring: Df = 2, F = 3.239 P = 0.048; for adult females: Df = 2, F = 8.459 P < 0.001) revealed the need for a test without assumption of homogenous variances. We thus performed pairwise t-tests with non-pooled standard deviations to analyse whether the treatments differ in the point in time at which the highest individual densities of a certain age class were observed. The same method was used to determine differences between the treatments regarding the total number of dispersing adult females and nest depth. All p-values resulting from these pairwise t-tests were corrected for multiple testing using the Benjamini and Hochberg (1995) method. Linear models were used to test whether (a) the time points at which the highest densities of the different age classes were determined, (b) the total number of dispersing adult females, and (c) the nest digging depth differed significantly between the two humidities tested in both experiments (interaction of "dry" vs "normal" substrate, and of the humidity experiment vs the selection experiment). To assess whether the dispersal timing of adult females differed between the treatments of both experiments, we analysed the dispersal day data using a Cox proportional hazards model likelihood ratio test (Therneau and Grambsch, 2000).

Behavioural Data Analyses
Behavioural data were analysed using generalised linear mixed models (GLMMs) with binomial error distribution and logitlink function. For this analysis we focused on the general activity, grooming, cannibalism, entrance blocking and balling behaviours of the beetles (see (Nuotclà et al., 2019) for a full ethogram of X. saxesenii). To examine the effects of the humidity treatment ("dry, " "normal" or "humid") and time since nest initiation ("nest age") on the different behaviours of the nest members, the frequency of the respective behaviour was set as the response variable, and the humidity treatment, nest age and their interaction served as explanatory variables. As nests were measured repeatedly over multiple days, we included the nest ID as a random variable. We performed loglikelihood tests to examine the significance of the explanatory variables. Stepwise backward elimination of non-significant terms was used to simplify the maximal model containing the interaction of treatment and nest age. Overdispersion was corrected for by incorporating an additional observation-level random variable in the model (Browne et al., 2005;Engqvist, 2005;Bolker et al., 2009).

Analysis of Molecular Data
Data files containing the attained zOTU (zero-radius Operational Taxonomic Unit; strictly speaking the amplicon sequence variant found by sequencing, in a broader sense the clearly distinguishable taxa) table, taxonomic table and sample data were analysed using the software R through merging into a phyloseq object (see Supplementary Material for information about the bioinformatics processing). The amplicon sequences of the fungi Chaetomium globosum and Penicillium sp. were excluded from the analysis since they were overabundant in all samples relative to other fungal species. DNA of these fungi is probably overabundant because they produce high amounts of spores that are passively transmitted on the surface of the beetles. Also, fast growing fungi such as Chaetomium globosum and Penicillium sp. may have higher rRNA copy numbers than slow-growing taxa (e.g., the ambrosia fungus R. sulphurea), as has been shown for prokaryotes (Maleszka and Clark-Walker, 1993;Weider et al., 2005). Similarly, the parasitic bacteria Wolbachia sp. where overrepresented in the bacterial 16S ribosomal RNA dataset due to their high numbers contained in the beetles' cells. We decided to exclude Wolbachia amplicon sequence variants to get a better resolution of the remaining species, since our focus was mainly on the microbial community that lives within the nest. We ran a GLMM with nest ID as random variable assuming a Poisson error distribution (Bolker et al., 2009) to test the influence of the humidity treatment ("dry" vs "normal" vs "humid") and time of dispersal ("early disperser" vs "late disperser") on the microbial community (number of observed zOTU's). Next, we performed a mixed non-metric multidimensional scaling (NMDS) and calculated the Bray-Curtis dissimilarity of taxa abundances between samples (Clarke et al., 2006). A permutational ANOVA test with 999 permutations was conducted using the R package vegan (Oksanen et al., 2016) to compare microbial communities between the treatments and time of dispersal, including "nest ID" as random variable. We ran another set of GLMM's to test whether there were differences depending on humidity treatment and dispersal timing between the relative abundance of carried ambrosia fungi and all other fungi. This enabled us also to determine whether the relative abundance of the two ambrosia fungi, R. sulphurea and R. canadensis, varied with these factors. Here, the relative read abundances of the fungi where set as the response variable, and the humidity treatment, dispersal timing and their interaction served as explanatory variables. The analysis followed the method described earlier for behavioural data. Post-hoc Tukey HSD tests with correction for multiple testing following Benjamini and Hochberg (1995) were used to describe differences between the treatments and between dispersal timings.
We should like to point out that the results of whole community analyses need to be interpreted with caution since the relative read abundance determined by analysis of whole beetles may not adequately represent the community that a beetle transmits to a new nest due to over-or underrepresentation of certain species. In addition, the ecological importance of most non-ambrosia mutualists is unknown. Therefore, to enable conclusions about the influence of habitat conditions on the whole microbial community, future studies should rather focus on the analysis of samples dissected from the mycangia alone, as the beetles actively spread material contained in them onto the walls of their newly founded nests. The present study reports the community composition found when crushing whole beetles, hence for the mentioned issues we only draw conclusions about the read abundance of the two known garden mutualists relative to each other; their relative abundance is likely determined mainly by the material contained within the mycangia and the guts (thus either purposely transmitted or previously ingested for food from the garden), and to a much lesser degree by accidental surface contamination. Besides this, our analysis of species richness for whole beetles may provide important clues about the influence of habitat on the microbial community, as these results are not affected by over-or underrepresentation of certain species; apart from the ambrosia fungi, we only determined the diversity of microbial species contained in each nest when a beetle disperses (see Supplementary Material for more details on the analysis of the sequencing output).

Nest Development
In the humidity experiment, nests reared in "normal" substrate reached their highest individual density earlier than those reared in "dry" (larvae P = 0.028; adult females P = 0.004) or "humid" substrate (larvae P = 0.057; adult females P = 0.027). The day at which individual density peaked did not differ significantly between the "humid" and "dry" nests in this experiment (larvae P > 0.1; adult females P = 0.069; Figures 1A-D).
The selection experiment showed that after five generations reared in "dry" substrate, the beetles showed a significantly delayed peak nest density, both in nests reared for the final test in "dry" substrate (larvae P < 0.001; adult females P = 0. 004) and in those reared in "normal" substrate (significant for larvae only: larvae P = 0.041; adult females P = 0.1). For these analyses, the intervals between nest founding and peak density were compared to the corresponding intervals in "normal" substrate in the humidity experiment, which served as the baseline. There was no difference in this parameter between nests from the selection line compared between the "dry" and "normal" test substrate (P > 0.1). A linear model checking for an interaction between treatment ("dry" vs "normal") and experiment (humidity experiment vs selection experiment) regarding the time point of peak nest density showed significant effects of rearing the beetles over multiple generations under dry conditions (larvae DF residuals = 58, F = 5.591, P = 0.021; adult females DF residuals = 58, F = 5.652, P = 0.021).
Visual inspection of eggs over time did not reveal any second egg batches after the first adult daughters were visible in the 13 "normal" and 13 "humid" nests during the humidity experiment, but 1 of 23 nests reared in "dry" substrate contained eggs at this late nest stage. In the selection experiment, 15 of 19 "dry" substrate nests and 4 of 7 "normal" substrate nests contained late egg batches in the final test.
Nests reared in "dry" substrate during the humidity experiment and nests reared in both "dry" and "normal" substrate in the final test of the selection experiment were dug significantly deeper into the substrate than those reared in "normal" substrate in the humidity experiment, which served as baseline (all P < 0.001; Figure 1E), whereas there was no difference in nest depth between "dry" and "normal" substrate conditions in the final test of the selection experiment test (P = 0.129). Nest depth did not differ between "normal" and "humid" substrate conditions in the humidity experiment (P = 402). A linear model used to evaluate the effect of five generations of "dry" substrate rearing on nest depth revealed a significant interaction between treatment ("normal" vs "dry") and experiment (humidity experiment vs selection experiment; DF residuals = 56, F = 13.252, P < 0.001).

Fitness and Timing of Dispersal
In the humidity experiment, significantly more dispersing females were produced in nests reared in "normal" substrate than in those reared in "dry" (P < 0.001) or "humid" (P = 0.017) substrates, whereas the latter two did not differ from each other (P = 0.208; Figure 2A). Nests reared in both "dry" and "normal" substrate in the final test of the selection experiment produced significantly more dispersing females than the nests of all three treatments in the humidity experiment (all P < 0.05), whereas they did not differ from each other (P = 0.248). There was no significant interaction between treatment ("normal" vs. "dry") and experiment (humidity experiment vs. selection experiment) on the total number of dispersing females (DF residuals = 58, F = 2.8177, P = 0.099; Figure 2A).
A Cox proportional hazards model (n = 1564 dispersing beetles; robust score test = 23.46; P < 0.001) revealed that in the humidity experiment, female dispersal was delayed in nests reared in "dry" (P < 0.001) compared to "normal" substrate, which was not true for the comparison between "humid" and "normal" substrate (P = 0.496). The same test also showed that female dispersal in nests reared in both "dry" (P < 0.001) and "normal" (P < 0.001) substrate in the final test of the selection experiment was delayed when compared to the nests reared in "normal" substrate in the humidity experiment, which served as a baseline ( Figure 2B).

Behaviour
GLMMs of total behavioural activity (all behaviours combined) indicated that the adult females were generally more active under "dry" than under "normal" conditions (P = 0.006), whereas there was no difference in the quantity of activity between the FIGURE 1 | Medians and interquartile ranges of relevant nest development parameters are displayed for three substrate humidities ("dry" = brown, "normal" = green, and "humid" = blue) measured during either the humidity experiment (A-E) or during the selection experiment (C-E). The humidity experiment tested the influence of different substrates on first generation nests, whereas the selection experiment tested whether the beetles develop differently in "normal" or "dry" substrate after they were reared over five generations in "dry" substrate. Panel (A) shows sub-adult (pupae and larvae) and panel (B) shows adult female peak densities for 20 day intervals. Numbers on top indicate the number of cumulative observations that were made for each treatment during each interval. Curves indicate regressions modelled as y = f(ax+bxˆ2+cxˆ3+d) for all data of each treatment, to illustrate the overall development of individual density across the treatments. For the statistical analysis we calculated the points in time of the highest individual density for every individual nest [shown in panels (C,D)]. Panel (E) shows how deep the beetles dug into the substrate in both experiments. Different lower-case letters in the top line of panels (C-E) indicate statistically significant differences within each panel (t-tests, corrected for multiple testing; P < 0.05).

FIGURE 2 | Panel (A)
illustrates the overall fitness impact of the three tested substrate humidities, indicated by medians and interquartile ranges of the total number of dispersing females per nest (logarithmic scale; "dry" = brown, "normal" = green, "humid" = blue). Different lower-case letters in the top line indicate statistically significant differences (t-tests corrected for multiple testing; P < 0.05). Panel (B) shows differences in the length of dispersal delay of adult females for both experiments and all treatments. Solid lines represent first generation nests of the humidity experiment, whereas dotted lines represent nests that had been reared for a final test in either "dry" (brown) or "normal" (green) substrate after the beetles had been reared in dry substrate for five generations (selection experiment).
"normal" and "humid" treatments (P = 0.478). Larvae reared in "dry" conditions were generally more active than those reared in "normal" medium (P = 0.004). Adult females tended to get more active with increasing nest age under "normal" and "humid" conditions of the humidity experiment (P = 0.06), whereas this trend was reversed in females under "dry" conditions; this was revealed by a significant interaction between nest age and humidity treatment (P = 0.01). Larvae became less active over time in all treatments (P = 0.012; see Supplementary Figure 1 for frequencies of relevant behaviours, and Supplementary Tables 4, 5 for model outputs).
Female grooming did not differ in frequency between the humidity treatments and this factor was removed from the final model. A separate GLMM for larval grooming showed that they groomed less in "dry" (P = 0.018) and "humid" (P = 0.038) than in "normal" conditions. Both, adult females (P < 0.001) and larvae (P = 0.002) generally groomed less the older the nests where. However, a significant positive interaction between nest age and humidity treatment indicates that this decrease over time was less strong in larvae reared under "dry" (P = 0.008) and "humid" (P = 0.028) conditions than in those reared in "normal" substrate.
Female cannibalism on nestmates occurred more under "humid" than under "normal" conditions (P = 0.009), whereas "normal" and "dry" conditions did not differ from each other (P = 0.565). Cannibalism by larvae did not differ between the treatments and did not change with nest age. Adult females cannibalised less with increasing nest age (P = 0.001). The frequency in which the entrance tunnel was blocked by an adult female did not differ between treatments and did not change with the course of time. Balling behaviour was generally shown more often by larvae under "dry" (P = 0.040) and "humid" conditions (P = 0.011) than in nests reared in "normal" substrate and its frequency decreased over time (P = 0.005).

Microbial Species Composition
Microbial species richness was approximated by analysing the zOTU richness (see Methods). The number of fungus 28S ribosomal RNA zOTUs in all samples ranged from 5 to 20, whereas the number of bacterial 16S ribosomal RNA zOTUs ranged from 48 to 257. GLMMs revealed a nonsignificant interaction between the humidity treatment ("normal" (reference) vs "dry" vs "humid") and the time of dispersal ("early" (reference) vs "late") for the fungal richness (GLMM: P = 0.062), and a significant interaction for the bacterial richness (P = 0.004). Post-hoc tests revealed that nests reared in "humid" substrate contained significantly more fungus species ("early" and "late" dispersers combined) than the ones reared in "dry" (TukeyHSD: P = 0.010) or "normal" (P = 0.048) substrate (no statistical difference between "early" and "late"). Fungal species richness did not differ between "normal" and "dry" substrate nests, and there was no difference in bacterial species richness between any of the three humidity treatments (all P > 0.1; see Figures 3, 4 and Supplementary Table 1).
After the exclusion of the overrepresented Penicillium sp. and Chaetomium globosum, ten dominant fungus taxa with a mean relative abundance (MRA) of over 0.5% could be assigned. The family Ophiostomatacea was represented with the two important fungus garden mutualists Raffaelea sulphurea and R. canadensis, and with a member of the genus Sporothrix that is potentially associated with ambrosia beetles (Harrington et al., 2010;Oranen, 2013). We found two fungus garden pathogens of the family Trichocomaceae, Talaromyces rugulosus and Aspergillus flavus. All other taxa where common saprobionts: Petriella sp. (Microascaceae), Aureobasidium leucospermi, Alternaria sp., Cladosporium sp., and a member of the Nectriaceae that could not be determined more specifically (see Figure 3A and Supplementary Table 2).
The overall microbial community composition carried by dispersing adult females neither significantly differed between the humidity treatments ("normal" (reference), "dry" and "humid"), nor for the time of dispersal ("early" vs "late"; PERMANOVA: all P > 0.1). Plotting the Bray-Curtis dissimilarity in NMDS plots also illustrated no obvious separation of the samples in "treatment" or "time of dispersal" ( Supplementary  Figures 2A,C). However, beetles dispersing from "normal" substrate nests had significantly higher read numbers for the two ambrosia fungi R. sulphurea and R. canadensis than those dispersing from "dry" (GLMM with TukeyHSD; P = 0.005) or "humid" (P = 0.043) substrate nests, whereas there was no difference between "humid" and "dry" substrate treatments in this respect (P = 0.761). Late dispersers carried more ambrosia fungi than those leaving early (P < 0.001), and there was a significant interaction effect of humidity treatment ("dry" vs "normal" vs "humid") and the time of dispersal ("early" vs. "late") on the ratio of ambrosia fungi to all other fungi (P < 0.001).
The ratio of the two ambrosia fungi R. sulphurea and R. canadensis tended to be lower in beetles that dispersed from "humid" nests (P = 0.055), and it was significantly lower in those dispersed from "dry" substrate (P < 0.001), than the corresponding ratio of beetles dispersing from "normal" substrate. There was no significant difference in the ratio of these two fungi between beetles dispersing from the "humid" and "dry" treatments (P = 0.146), and no significant influence of dispersal time on the ambrosia fungus ratio ("early" vs "late": P = 0.3; factor removed from final model; Figure 4B).

DISCUSSION
The results of the humidity experiment indicate that under "humid" and "dry" nest substrate conditions, which correspond to either very freshly dead or desiccated parts of long-dead trees, foundresses may suffer considerable fitness loss compared to "normal" humidity conditions. This is due to decreased offspring numbers and a delayed maturation time of the offspring (Figures 1A,C, 2A). Delayed maturation time also caused later dispersal of adult daughters in "dry" substrate ( Figure 2B) and larval density in these conditions was permanently lower and never reached a peak comparable to those reached under "normal" or "humid" conditions ( Figures 1A,C). Besides the considerably slowed development, we also observed a more steady dispersal pattern in "dry" substrate compared to nests reared in "normal" or "humid" substrate, where the timing of dispersal seems to be more clustered (Figure 2B).
The altered nest development and dispersal patterns under suboptimal "humid" and, especially, "dry" conditions (Figures 1, 2) might be explained by changes in the microbial community found in these nests. The relative abundance of ambrosia fungi reads compared to reads of other fungus species carried by dispersers in the "dry" and "humid" treatment nests was lower than for those in the "normal" treatment ( Figure 4B). This may indicate that the fungus garden of these suboptimal substrates yielded less food for the beetles than the "normal" condition. We found that beetles from nests reared on "humid" substrate carried a significantly more variable fungus community than those dispersing from "normal" or "dry" substrate nests. Humid substrate seems to allow more fungus species to thrive, possibly leading to increased competition between them, which might put the mutualistic ambrosia fungi at a disadvantage (see Figure 4A). In contrast, dry initial conditions might cause lower growth of the mutualistic ambrosia fungi, which thrive better at higher humidity (Zimmermann and Butin, 1973). Thus, both suboptimal conditions probably yielded less food for the beetles, but for different reasons.
Importantly, the ambrosia fungus species Raffaelea canadensis represented a much greater proportion of fungi carried by dispersing beetles from "dry" nests than from those dispersing from "normal" nests, whereas the latter carried Raffaelea sulphurea as the dominating mutualistic fungus species when dispersing from their natal nest (Figures 3A, 4B). Experimental data indicate that R. canadensis is a slower growing fungus than R. sulphurea, but it grows much better under dry than normal conditions (Nuotclà and Taborsky, unpubl. data). We therefore hypothesize that carrying multiple species of mutualists that are adapted to different humidity regimes may help the beetles to thrive in variable conditions. Such mutualist complementarity was reported also for the fungus-associated bark beetle Dendroctonus ponderosae, which carries at least two associated ambrosia fungus species that vary in abundance depending on the temperature regime (Six and Bentz, 2007).
The ephemerality of dead wood has been suggested to be a crucial factor impeding social evolution in ambrosia beetles. It limits the potential nest lifetime and thus may lower the chances for generational overlap and reduce the incentive for offspring to remain philopatric, cooperate and reproduce in their natal nest at a later stage (Alexander et al., 1991;Kirkendall et al., 1997). Only few examples are known in ambrosia beetles where this limitation does not apply. Amongst those we find some of the most remarkable examples of social complexity for ambrosia beetles, as for instance in the platypodine species Trachyostus ghanensis or Austroplatypus incompertus, the nests of which can survive many years inside living trees and can harbour multiple overlapping offspring generations (Roberts, 1960;Kent and Simpson, 1992). FIGURE 3 | Relative read abundance of the major fungus (A) and (B) bacteria taxa carried by dispersing females of the humidity experiment, differentiated by dispersal time ("early" or "late") and humidity treatment ("dry," "normal" or "humid").
The species of the genera Ambrosiophilus and Ambrosiodmus have overcome the problem of dwindling resources in aging dead trees by associating with a highly competitive wooddecaying fungus. This has led to long lived nests that harbour multiple generations of offspring (Kasson et al., 2016). Similarly, carrying a variety of complementary mutualistic fungi may buffer environmental conditions and enhance the viability of the alloparenting strategy of X. saxesenii by increasing the timespan in which the wood can be used for fungiculture. Initially, the beetles can rely on the fast growing and highly productive R. sulphurea, but over time the primary abundance of ambrosia fungi in the gallery may change to the more dry-tolerant R. canadensis, depending on humidity. Prolonged nest viability should increase the incentive for adult daughters to stay in the natal gallery and help raising sisters, since it increases the survival chances of the latter. Thus, even if our "dry" treatment initially led to less and more slowly growing offspring, the future prospects for the daughters might have been better due to a more favourable fungus composition than in the "humid" treatment, where the ambrosia fungi may be outcompeted by other microorganisms.
Prolonged nest viability might also allow daughters to eventually take over the nest from their mother. In the "dry" treatment of the humidity experiment we found one case where second egg batches occurred, which might indicate that daughters have fostered offspring in their maternal nest. In the selection experiment, after we had reared the beetles over five generations in "dry" conditions, 73% of nests exhibited late egg batches. Nevertheless, we are currently unable to determine whether these eggs were indeed produced by daughters, or whether they reflected second egg batches produced by their mother. In any case, these additional clutches should raise the total fitness across a nest, which is corroborated by the considerable increase of the total number of dispersing adult females in these nests.
Enhanced long term offspring production in dry conditions was confirmed by the selection experiment, where after keeping the beetles in the "dry" substrate treatment for five generations, the final test yielded much higher numbers of dispersing beetles in both test conditions, "dry" and "normal, " than any of the treatments in the humidity experiment (Figure 2A). The enhanced productivity was probably linked to the fungus garden composition of the nests, with the dryness-resistant R. canadensis becoming the dominating mutualistic fungus species. Visual inspection of galleries in the humidity experiment indicated a yellowish colour of the fungus garden especially in the "normal" and "humid" treatment conditions, which is typically attributed to metabolic compounds produced by the mutualist R. sulphurea (hence its name). In contrast, the fungus garden of nests at the late stages of the "dry" condition in the humidity experiment, and at both conditions of the final test in the selection experiment, had mostly a whitish FIGURE 4 | Panel (A) illustrates the numbers of zero radius Operational Taxonomic Units (zOTU, ≈ number of clearly distinguishable species) for fungus and bacteria species that are carried by first ("early") or last ("late") dispersing females from nests reared in "normal," "dry" and "humid" substrate during the humidity experiment. Panel (B) illustrates the relative read abundance of ambrosia fungi over all fungi, and the relative read abundance of the two main ambrosia fungus species carried by Xyleborinus saxesenii females, Raffaelea sulphurea and Raffaelea canadensis. Medians and interquartile ranges are shown. Different lower case letters in the top line indicate statistically significant differences within each panel (TukeyHSD; P < 0.05).
colour, presumably indicating the dryness-condition specialist R. canadensis. Since this fungus grows only slowly, the beetles may reach adulthood comparatively late due to nutritional limitation. But this drawback is compensated by longer nest maintenance and consequently higher productivity, as under dry conditions these ambrosia fungi may be less challenged by competing microorganisms.
The higher productivity of nests after selection in "dry" substrate, relates also to the enhanced utilisation of the offered substrate ( Figure 1E). Already first generation foundresses in the humidity experiment dug deeper into dry substrate and the chambers excavated by the larvae were thus nearer to the bottom of the experimental tubes in "dry" than "normal" and "humid" conditions. This might reflect a strategy to reach deeper into the humid core of the wood. It could be that a nest foundress digs as long as it takes for the fungus garden to grow enough biomass to cover the beetles' nitrogen requirements (wood being a nitrogen-poor substrate) before laying the eggs. Ophiostomatoid fungi are known to concentrate nitrogen, phosphorus and other trace elements from the surrounding wood and to provide it to the beetles trough fungal tissues in the beetles' tunnels (Six and Elser, 2019). In accordance with this idea, when fungus is experimentally removed, Dendroctonus bark beetles are known to dig longer tunnels to cover their nitrogen requirements (Ayres et al., 2000). Reversing the humidity back from "dry" to "normal" conditions in the final test of the selection experiment did not reverse the pattern of digging depth, which might indicate that this experimental selection resulted in permanent changes of the microbial community.
Not only nest foundress digging behaviour changed according to the humidity conditions, but also the offspring seem to adjust their behavioural patterns. Larvae were more active and showed more balling behaviour in both sub optimal treatment conditions. Balling is a crucial nest keeping behaviour only shown by larvae, which facilitates the removal of debris from the nest by adult females. Increased nest depth in "dry" and accelerated grow of competing fungi in "humid" nests thus seem to necessitate more work by the larvae. Besides, adult females notably increased their cannibalisation of larvae in "humid" nests when compared to such reared in "normal" substrate. Cannibalisation was described to be a form of destructive sanitation that allows removal of nestmates that are infected by pathogenic fungi (Nuotclà et al., 2019). Increased cannibalisation rates might be thus further evidence for increased microbial competition in humid wood. However, we found no increased adult female grooming frequency which would also be predicted in the presence of pathogens.
In conclusion, our data show that when the substrate is very dry, the ambrosia fungus garden is mainly composed of less productive, drought resistant fungi, which leads to slower offspring development but may also limit the invasion of antagonistic fungus species. This obviously enables long-lasting nests and increases total offspring numbers, perhaps at least partly due to some daughters refraining from dispersal and instead producing own offspring in the natal nest. The success of this strategy may depend on the availability of alternative nesting possibilities, dispersal conditions and the progression of the season. Hence, the dry conditions that finally render higher offspring numbers but retard the offspring development, may work out well early in the season but rather reflect a "best-of-abad-job" response when the season has further progressed.
We further demonstrate that the substrate choice of a foundress not only has direct consequences for the cooperative investment of her daughters but can have long-lasting effects for future generations, since primary fungal mutualists can be selected depending on substrate humidity. It seems prudent for dispersing offspring to seek wood conditions matching those in their natal nest in order to provide optimal conditions for the microbial mutualist community they bring along. Since nest longevity and productivity appear to depend heavily on the mutualist community composition, which is also linked to philopatry and cooperative investment, the incentive for habitat matching may have selected for cooperative traits over evolutionary time. Testing this "habitat matching hypothesis" in future experiments could help to answer whether primary fungal mutualists can act as drivers of sociality in ambrosia beetles.

DATA AVAILABILITY STATEMENT
Raw data on the nest member density, behavior frequency, digging depth, and dispersal as well as the molecular reference files and shell scripts for bioinformatics processing can be found in the Supplementary Material. The nucleotide data associated with this study are accessible at the European Nucleotide Archive (accession number PRJEB44223; https://www.ebi.ac.uk/ ena/browser/view/PRJEB44223).

AUTHOR CONTRIBUTIONS
JN and MT conceived and designed the experiments. JN carried out the experiments and analysed the data. JD developed and carried out the molecular analysis and analysed the molecular data. JN, JD, and MT wrote the manuscript. All authors contributed to the article and approved the submitted version.

FUNDING
This research was supported by grants from the Swiss National Science Foundation (grant numbers 31003A_156152 and 31003A_176174) to MT. Funds for the molecular analysis and the work of JD where provided by a Marie Curie Intra-European Fellowship (IEF; project number 626279) and by the German Research Foundation (DFG; Emmy Noether grant number BI 1956/1-1), both granted to Peter Biedermann.