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

class B:
    def __init__(self, txt: str):
        self.y: A = None
        self.z: A = None
        self.t: D = None
        self.txt = txt

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

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

b = A("b")
c = B("c")
a = C("a")
f = D("f")
m = B("m")

b.u = m
b.s = a
c.y = b
c.z = b
c.t = f
a.x = c
f.w = c
f.z = a
f.s = a
f.q = b
m.y = b
m.z = b
m.t = f
assert f.q.s.x.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.s: C = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.y: A = None
        self.z: A = None
        self.t: D = None
        self.txt = txt

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

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

b = A("b")
c = B("c")
a = C("a")
f = D("f")
m = B("m")

b.u = m
b.s = a
c.y = b
c.z = b
c.t = f
a.x = c
f.w = c
f.z = a
f.s = a
f.q = b
m.y = b
m.z = b
m.t = f
assert f.q.s.x.txt == "c"