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

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

c = A("c")
l = B("l")
f = B("f")
h = B("h")

c.x = h
c.y = l
l.p = f
f.p = h
h.p = f
assert h.p.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.y: B = None
        self.txt = txt

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

c = A("c")
l = B("l")
f = B("f")
h = B("h")

c.x = h
c.y = l
l.p = f
f.p = h
h.p = f
assert h.p.p.p.p.txt == "h"