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

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

k = A("k")
h = B("h")
b = A("b")
m = A("m")
l = A("l")
d = B("d")

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

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

k = A("k")
h = B("h")
b = A("b")
m = A("m")
l = A("l")
d = B("d")

k.q = d
k.u = m
h.r = d
b.q = d
b.u = m
m.q = d
m.u = k
l.q = h
l.u = b
d.r = h
assert b.u.q.r.txt == "h"