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

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

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

class D:
    def __init__(self, txt: str):
        self.r: A = None
        self.w: D = None
        self.x: A = None
        self.txt = txt

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

h.y = d
c.o = n
g.s = k
g.z = h
k.r = h
k.x = h
k.w = f
n.o = c
f.r = d
f.x = d
f.w = k
d.y = h
assert g.z.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.r: A = None
        self.w: D = None
        self.x: A = None
        self.txt = txt

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

h.y = d
c.o = n
g.s = k
g.z = h
k.r = h
k.x = h
k.w = f
n.o = c
f.r = d
f.x = d
f.w = k
d.y = h
assert g.z.y.y.txt == "h"