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

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

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

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

j = A("j")
h = B("h")
n = C("n")
m = D("m")

j.y = n
h.u = n
h.q = m
n.q = h
n.x = j
n.s = j
n.p = m
m.r = j
assert h.q.r.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.txt = txt

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

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

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

j = A("j")
h = B("h")
n = C("n")
m = D("m")

j.y = n
h.u = n
h.q = m
n.q = h
n.x = j
n.s = j
n.p = m
m.r = j
assert h.q.r.y.txt == "n"