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

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

e = A("e")
d = B("d")
b = A("b")
h = B("h")

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

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

e = A("e")
d = B("d")
b = A("b")
h = B("h")

e.y = h
d.r = h
b.y = d
h.r = d
assert e.y.r.r.r.txt == "d"