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

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

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

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

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

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

b.q = d
b.u = k
h.r = b
h.o = d
d.q = b
d.u = k
k.r = d
k.o = d
n.r = d
n.o = d
assert d.q.u.r.q.q.txt == "d"