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

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

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

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

e = A("e")
m = B("m")
c = C("c")
k = D("k")
i = B("i")
f = C("f")
g = A("g")

e.o = c
m.z = i
m.x = i
c.y = f
c.q = m
k.z = e
i.z = m
i.x = m
f.y = c
f.q = m
g.o = f
assert m.z.x.z.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.txt = txt

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

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

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

e = A("e")
m = B("m")
c = C("c")
k = D("k")
i = B("i")
f = C("f")
g = A("g")

e.o = c
m.z = i
m.x = i
c.y = f
c.q = m
k.z = e
i.z = m
i.x = m
f.y = c
f.q = m
g.o = f
assert m.z.x.z.txt == "i"