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

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

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

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

e = A("e")
f = B("f")
k = C("k")
j = D("j")

e.y = j
e.w = j
e.r = k
f.r = e
f.y = j
k.v = j
k.r = e
j.z = f
j.u = f
j.q = k
assert k.v.q.v.txt == "
class A:
    def __init__(self, txt: str):
        self.y: D = None
        self.w: D = None
        self.r: C = None
        self.txt = txt

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

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

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

e = A("e")
f = B("f")
k = C("k")
j = D("j")

e.y = j
e.w = j
e.r = k
f.r = e
f.y = j
k.v = j
k.r = e
j.z = f
j.u = f
j.q = k
assert k.v.q.v.txt == "j"