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

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

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

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

g = A("g")
a = B("a")
d = C("d")
e = D("e")
f = B("f")

g.q = f
a.r = e
a.z = d
a.w = f
d.s = g
d.z = f
e.u = a
e.x = a
e.v = d
f.r = e
f.z = d
f.w = a
assert f.z.z.r.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

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

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

g = A("g")
a = B("a")
d = C("d")
e = D("e")
f = B("f")

g.q = f
a.r = e
a.z = d
a.w = f
d.s = g
d.z = f
e.u = a
e.x = a
e.v = d
f.r = e
f.z = d
f.w = a
assert f.z.z.r.txt == "e"