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

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

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

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

m = A("m")
l = B("l")
e = C("e")
h = D("h")

m.p = e
m.q = h
l.q = m
l.s = h
e.v = l
e.x = h
h.x = l
assert h.x.s.x.q.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.q: D = None
        self.txt = txt

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

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

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

m = A("m")
l = B("l")
e = C("e")
h = D("h")

m.p = e
m.q = h
l.q = m
l.s = h
e.v = l
e.x = h
h.x = l
assert h.x.s.x.q.txt == "m"