class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.q: B = None
        self.r: B = None
        self.txt = txt

f = A("f")
j = B("j")
h = A("h")
g = B("g")
b = A("b")
d = A("d")
m = B("m")

f.x = m
j.q = g
j.r = g
h.x = m
g.q = j
g.r = j
b.x = g
d.x = m
m.q = g
m.r = g
assert m.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.q: B = None
        self.r: B = None
        self.txt = txt

f = A("f")
j = B("j")
h = A("h")
g = B("g")
b = A("b")
d = A("d")
m = B("m")

f.x = m
j.q = g
j.r = g
h.x = m
g.q = j
g.r = j
b.x = g
d.x = m
m.q = g
m.r = g
assert m.q.q.q.txt == "g"