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

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

h = A("h")
c = B("c")
a = B("a")

h.p = a
h.z = a
c.u = h
c.p = a
a.u = h
a.p = c
assert a.u.z.u.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.z: B = None
        self.txt = txt

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

h = A("h")
c = B("c")
a = B("a")

h.p = a
h.z = a
c.u = h
c.p = a
a.u = h
a.p = c
assert a.u.z.u.txt == "h"