class A:
    def __init__(self, txt: str):
        self.p: D = None
        self.q: D = None
        self.txt = txt

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

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

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

j = A("j")
m = B("m")
l = C("l")
c = D("c")
d = C("d")

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

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

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

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

j = A("j")
m = B("m")
l = C("l")
c = D("c")
d = C("d")

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