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

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

class C:
    def __init__(self, txt: str):
        self.p: D = None
        self.y: B = None
        self.u: A = None
        self.z: A = None
        self.txt = txt

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

e = A("e")
k = B("k")
h = C("h")
c = D("c")
a = A("a")
d = A("d")

e.o = a
k.q = h
h.p = c
h.y = k
h.u = d
h.z = e
c.p = d
c.y = a
a.o = d
d.o = a
assert c.y.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.p: D = None
        self.y: B = None
        self.u: A = None
        self.z: A = None
        self.txt = txt

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

e = A("e")
k = B("k")
h = C("h")
c = D("c")
a = A("a")
d = A("d")

e.o = a
k.q = h
h.p = c
h.y = k
h.u = d
h.z = e
c.p = d
c.y = a
a.o = d
d.o = a
assert c.y.o.o.o.txt == "d"