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

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

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

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

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

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

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

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

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

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

f.z = e
f.v = d
d.u = g
d.z = g
d.r = e
g.q = c
g.w = d
c.y = d
c.q = g
e.z = f
e.v = d
b.y = d
b.q = g
assert f.v.u.q.q.txt == "g"