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

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

d = A("d")
g = B("g")
j = B("j")
l = A("l")
e = A("e")
b = A("b")

d.s = l
g.p = b
j.p = l
l.s = e
e.s = l
b.s = e
assert e.s.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.txt = txt

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

d = A("d")
g = B("g")
j = B("j")
l = A("l")
e = A("e")
b = A("b")

d.s = l
g.p = b
j.p = l
l.s = e
e.s = l
b.s = e
assert e.s.s.s.s.s.txt == "l"