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

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

d = A("d")
f = B("f")
l = B("l")
a = B("a")

d.s = l
d.p = a
f.y = a
l.y = f
a.y = l
assert a.y.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.p: B = None
        self.txt = txt

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

d = A("d")
f = B("f")
l = B("l")
a = B("a")

d.s = l
d.p = a
f.y = a
l.y = f
a.y = l
assert a.y.y.y.y.txt == "l"