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

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

j = A("j")
l = B("l")
a = A("a")
b = A("b")
i = A("i")
d = A("d")
n = A("n")
f = B("f")
m = B("m")

j.z = l
j.p = n
l.x = m
a.z = m
a.p = i
b.z = m
b.p = i
i.z = m
i.p = j
d.z = f
d.p = j
n.z = l
n.p = i
f.x = m
m.x = l
assert d.z.x.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.p: A = None
        self.txt = txt

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

j = A("j")
l = B("l")
a = A("a")
b = A("b")
i = A("i")
d = A("d")
n = A("n")
f = B("f")
m = B("m")

j.z = l
j.p = n
l.x = m
a.z = m
a.p = i
b.z = m
b.p = i
i.z = m
i.p = j
d.z = f
d.p = j
n.z = l
n.p = i
f.x = m
m.x = l
assert d.z.x.x.x.x.x.txt == "m"