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

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

h = A("h")
l = B("l")
k = A("k")
e = B("e")

h.y = k
l.p = k
l.r = e
k.y = h
e.p = h
e.r = l
assert e.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

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

h = A("h")
l = B("l")
k = A("k")
e = B("e")

h.y = k
l.p = k
l.r = e
k.y = h
e.p = h
e.r = l
assert e.r.r.r.txt == "l"