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

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

class C:
    def __init__(self, txt: str):
        self.v: B = None
        self.r: A = None
        self.w: D = None
        self.y: A = None
        self.txt = txt

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

n = A("n")
m = B("m")
c = C("c")
b = D("b")

n.u = c
n.w = c
n.s = c
n.r = b
m.w = b
c.v = m
c.r = n
c.y = n
c.w = b
b.q = n
b.p = m
assert b.q.r.p.txt == "
class A:
    def __init__(self, txt: str):
        self.u: C = None
        self.r: D = None
        self.w: C = None
        self.s: C = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.v: B = None
        self.r: A = None
        self.w: D = None
        self.y: A = None
        self.txt = txt

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

n = A("n")
m = B("m")
c = C("c")
b = D("b")

n.u = c
n.w = c
n.s = c
n.r = b
m.w = b
c.v = m
c.r = n
c.y = n
c.w = b
b.q = n
b.p = m
assert b.q.r.p.txt == "m"