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

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

e = A("e")
k = B("k")
d = A("d")
c = A("c")

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

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

e = A("e")
k = B("k")
d = A("d")
c = A("c")

e.r = k
k.r = c
d.r = k
c.r = k
assert e.r.r.r.txt == "k"