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

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

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

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

k = A("k")
a = B("a")
j = C("j")
f = D("f")
g = C("g")

k.v = a
k.o = a
a.r = g
a.q = k
j.w = g
j.r = f
j.o = k
f.z = a
g.w = j
g.r = f
g.o = k
assert k.v.r.w.r.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.o: B = None
        self.txt = txt

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

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

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

k = A("k")
a = B("a")
j = C("j")
f = D("f")
g = C("g")

k.v = a
k.o = a
a.r = g
a.q = k
j.w = g
j.r = f
j.o = k
f.z = a
g.w = j
g.r = f
g.o = k
assert k.v.r.w.r.txt == "f"