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

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

b = A("b")
d = B("d")
h = B("h")

b.o = h
d.q = h
d.t = h
h.q = d
h.t = d
assert d.q.t.q.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

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

b = A("b")
d = B("d")
h = B("h")

b.o = h
d.q = h
d.t = h
h.q = d
h.t = d
assert d.q.t.q.txt == "h"