class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.u: B = 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 = B("b")
a = A("a")
d = B("d")

k.r = h
k.u = b
h.r = d
b.r = d
a.r = d
a.u = h
d.r = b
assert b.r.r.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.u: B = 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 = B("b")
a = A("a")
d = B("d")

k.r = h
k.u = b
h.r = d
b.r = d
a.r = d
a.u = h
d.r = b
assert b.r.r.r.r.r.txt == "d"