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

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

i = A("i")
d = B("d")
n = B("n")
f = A("f")
k = B("k")
b = A("b")

i.s = f
d.z = n
d.p = f
n.z = k
n.p = b
f.s = b
k.z = d
k.p = b
b.s = f
assert i.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.z: B = None
        self.p: A = None
        self.txt = txt

i = A("i")
d = B("d")
n = B("n")
f = A("f")
k = B("k")
b = A("b")

i.s = f
d.z = n
d.p = f
n.z = k
n.p = b
f.s = b
k.z = d
k.p = b
b.s = f
assert i.s.s.s.txt == "f"