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

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

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

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

f = A("f")
g = B("g")
d = C("d")
k = D("k")
n = A("n")

f.y = g
g.z = n
g.o = k
g.t = d
d.o = f
d.s = n
k.y = d
n.y = g
assert g.z.y.o.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

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

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

f = A("f")
g = B("g")
d = C("d")
k = D("k")
n = A("n")

f.y = g
g.z = n
g.o = k
g.t = d
d.o = f
d.s = n
k.y = d
n.y = g
assert g.z.y.o.y.txt == "d"