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

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

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

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

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

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

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

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

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

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

b.r = c
g.v = c
g.u = b
c.y = f
c.z = f
c.u = b
c.v = g
f.v = g
f.q = b
f.s = b
assert f.v.v.u.r.txt == "c"