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

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

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

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

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

k.t = g
a.y = k
a.v = k
g.o = k
g.y = a
e.t = k
e.x = j
e.z = a
j.t = k
j.x = e
j.z = a
assert a.v.t.o.txt == "
class A:
    def __init__(self, txt: str):
        self.t: C = None
        self.txt = txt

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

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

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

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

k.t = g
a.y = k
a.v = k
g.o = k
g.y = a
e.t = k
e.x = j
e.z = a
j.t = k
j.x = e
j.z = a
assert a.v.t.o.txt == "k"