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

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

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

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

i = A("i")
d = B("d")
g = C("g")
k = D("k")

i.v = d
d.t = i
g.r = i
g.w = i
g.u = d
g.s = k
k.o = d
k.p = g
assert i.v.t.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.txt = txt

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

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

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

i = A("i")
d = B("d")
g = C("g")
k = D("k")

i.v = d
d.t = i
g.r = i
g.w = i
g.u = d
g.s = k
k.o = d
k.p = g
assert i.v.t.v.txt == "d"