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

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

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

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

m = A("m")
h = B("h")
l = C("l")
d = D("d")
n = B("n")
g = C("g")

m.o = l
h.t = n
h.z = n
h.y = m
l.z = n
l.r = g
d.z = l
d.x = l
n.t = h
n.z = h
n.y = m
g.z = n
g.r = l
assert l.z.y.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.txt = txt

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

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

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

m = A("m")
h = B("h")
l = C("l")
d = D("d")
n = B("n")
g = C("g")

m.o = l
h.t = n
h.z = n
h.y = m
l.z = n
l.r = g
d.z = l
d.x = l
n.t = h
n.z = h
n.y = m
g.z = n
g.r = l
assert l.z.y.o.txt == "l"