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

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

h = A("h")
e = B("e")
k = A("k")

h.x = k
h.p = k
e.z = k
k.x = h
k.p = h
assert e.z.p.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.p: A = None
        self.txt = txt

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

h = A("h")
e = B("e")
k = A("k")

h.x = k
h.p = k
e.z = k
k.x = h
k.p = h
assert e.z.p.x.txt == "k"