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

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

m = A("m")
l = B("l")
d = A("d")
g = A("g")
j = B("j")
c = B("c")

m.v = j
m.q = j
l.p = m
l.z = m
d.v = j
d.q = l
g.v = l
g.q = j
j.p = m
j.z = m
c.p = g
c.z = g
assert c.z.v.p.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.q: B = None
        self.txt = txt

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

m = A("m")
l = B("l")
d = A("d")
g = A("g")
j = B("j")
c = B("c")

m.v = j
m.q = j
l.p = m
l.z = m
d.v = j
d.q = l
g.v = l
g.q = j
j.p = m
j.z = m
c.p = g
c.z = g
assert c.z.v.p.txt == "m"