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

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

j = A("j")
i = B("i")
a = B("a")
b = A("b")
f = A("f")
h = A("h")

j.s = a
j.p = f
i.z = a
i.s = a
a.z = i
a.s = i
b.s = i
b.p = j
f.s = i
f.p = h
h.s = i
h.p = b
assert i.s.z.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.p: A = None
        self.txt = txt

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

j = A("j")
i = B("i")
a = B("a")
b = A("b")
f = A("f")
h = A("h")

j.s = a
j.p = f
i.z = a
i.s = a
a.z = i
a.s = i
b.s = i
b.p = j
f.s = i
f.p = h
h.s = i
h.p = b
assert i.s.z.s.s.s.txt == "a"