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

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

i = A("i")
d = B("d")
h = A("h")
l = B("l")
c = A("c")
n = A("n")

i.p = l
i.x = d
d.z = c
h.p = l
h.x = l
l.z = h
c.p = d
c.x = d
n.p = l
n.x = d
assert l.z.p.z.x.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.x: B = None
        self.txt = txt

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

i = A("i")
d = B("d")
h = A("h")
l = B("l")
c = A("c")
n = A("n")

i.p = l
i.x = d
d.z = c
h.p = l
h.x = l
l.z = h
c.p = d
c.x = d
n.p = l
n.x = d
assert l.z.p.z.x.txt == "l"