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

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

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

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

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

g.z = j
g.s = j
g.o = j
g.r = f
n.x = k
n.r = k
n.y = f
f.z = n
f.x = n
j.x = f
k.x = n
k.r = n
k.y = f
assert k.r.y.z.x.txt == "
class A:
    def __init__(self, txt: str):
        self.z: D = None
        self.s: D = None
        self.o: D = None
        self.r: C = None
        self.txt = txt

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

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

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

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

g.z = j
g.s = j
g.o = j
g.r = f
n.x = k
n.r = k
n.y = f
f.z = n
f.x = n
j.x = f
k.x = n
k.r = n
k.y = f
assert k.r.y.z.x.txt == "k"