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

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

d = A("d")
e = B("e")
c = B("c")
a = A("a")
b = B("b")
k = B("k")

d.s = a
e.p = b
c.p = b
a.s = d
b.p = c
k.p = c
assert b.p.p.p.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.txt = txt

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

d = A("d")
e = B("e")
c = B("c")
a = A("a")
b = B("b")
k = B("k")

d.s = a
e.p = b
c.p = b
a.s = d
b.p = c
k.p = c
assert b.p.p.p.p.p.p.txt == "b"