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

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

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

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

m = A("m")
b = B("b")
i = C("i")
g = D("g")
d = B("d")

m.u = g
m.s = b
b.y = g
b.w = d
b.t = d
b.x = i
i.w = b
i.t = m
g.q = d
g.w = b
d.y = g
d.w = b
d.t = b
d.x = i
assert d.y.q.x.t.txt == "
class A:
    def __init__(self, txt: str):
        self.u: D = None
        self.s: B = None
        self.txt = txt

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

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

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

m = A("m")
b = B("b")
i = C("i")
g = D("g")
d = B("d")

m.u = g
m.s = b
b.y = g
b.w = d
b.t = d
b.x = i
i.w = b
i.t = m
g.q = d
g.w = b
d.y = g
d.w = b
d.t = b
d.x = i
assert d.y.q.x.t.txt == "m"