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

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

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

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

d = A("d")
b = B("b")
c = C("c")
a = D("a")
g = B("g")
k = D("k")
n = A("n")

d.t = a
b.z = g
b.y = c
c.y = n
a.z = k
g.z = b
g.y = c
k.z = a
n.t = k
assert a.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.t: D = None
        self.txt = txt

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

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

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

d = A("d")
b = B("b")
c = C("c")
a = D("a")
g = B("g")
k = D("k")
n = A("n")

d.t = a
b.z = g
b.y = c
c.y = n
a.z = k
g.z = b
g.y = c
k.z = a
n.t = k
assert a.z.z.z.z.txt == "a"