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

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

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

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

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

e.o = d
e.w = d
e.q = g
h.y = e
h.r = e
h.x = d
d.r = e
i.x = e
m.x = e
g.x = e
a.x = e
k.y = e
k.r = e
k.x = d
c.x = e
assert a.x.q.x.o.r.q.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.q: D = None
        self.w: C = None
        self.txt = txt

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

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

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

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

e.o = d
e.w = d
e.q = g
h.y = e
h.r = e
h.x = d
d.r = e
i.x = e
m.x = e
g.x = e
a.x = e
k.y = e
k.r = e
k.x = d
c.x = e
assert a.x.q.x.o.r.q.txt == "g"