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

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

j = A("j")
c = B("c")
k = A("k")
m = A("m")

j.p = c
c.z = k
k.p = c
m.p = c
assert k.p.z.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

j = A("j")
c = B("c")
k = A("k")
m = A("m")

j.p = c
c.z = k
k.p = c
m.p = c
assert k.p.z.p.txt == "c"