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

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

d = A("d")
k = B("k")
e = B("e")
i = A("i")
a = B("a")
b = A("b")

d.x = k
k.r = e
e.r = a
i.x = k
a.r = k
b.x = a
assert k.r.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

d = A("d")
k = B("k")
e = B("e")
i = A("i")
a = B("a")
b = A("b")

d.x = k
k.r = e
e.r = a
i.x = k
a.r = k
b.x = a
assert k.r.r.r.r.txt == "e"