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

k = A("k")
j = B("j")
f = B("f")
a = B("a")

k.p = a
j.z = k
f.z = k
a.z = k
assert a.z.p.z.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

k = A("k")
j = B("j")
f = B("f")
a = B("a")

k.p = a
j.z = k
f.z = k
a.z = k
assert a.z.p.z.txt == "k"