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

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

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

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

m = A("m")
d = B("d")
g = C("g")
a = D("a")

m.r = d
m.q = a
m.w = g
d.s = m
g.t = m
g.x = m
g.s = m
g.p = m
a.v = d
a.s = g
assert m.r.s.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.q: D = None
        self.w: C = None
        self.txt = txt

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

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

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

m = A("m")
d = B("d")
g = C("g")
a = D("a")

m.r = d
m.q = a
m.w = g
d.s = m
g.t = m
g.x = m
g.s = m
g.p = m
a.v = d
a.s = g
assert m.r.s.r.txt == "d"