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.z: A = None
        self.y: A = None
        self.txt = txt

l = A("l")
i = B("i")
m = B("m")
d = B("d")
c = A("c")
a = A("a")
k = A("k")
j = A("j")

l.p = i
l.z = i
i.z = c
i.y = a
m.z = c
m.y = l
d.z = l
d.y = k
c.p = d
c.z = i
a.p = d
a.z = m
k.p = m
k.z = i
j.p = d
j.z = d
assert i.y.z.y.p.y.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.z: A = None
        self.y: A = None
        self.txt = txt

l = A("l")
i = B("i")
m = B("m")
d = B("d")
c = A("c")
a = A("a")
k = A("k")
j = A("j")

l.p = i
l.z = i
i.z = c
i.y = a
m.z = c
m.y = l
d.z = l
d.y = k
c.p = d
c.z = i
a.p = d
a.z = m
k.p = m
k.z = i
j.p = d
j.z = d
assert i.y.z.y.p.y.txt == "a"