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

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

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

d = A("d")
j = B("j")
g = C("g")
m = C("m")
l = A("l")
b = C("b")
k = C("k")
e = A("e")

d.o = m
d.r = m
d.q = j
j.o = l
j.w = d
g.x = d
m.x = d
l.o = g
l.r = g
l.q = j
b.x = e
k.x = l
e.o = b
e.r = b
e.q = j
assert g.x.r.x.o.x.r.x.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.q: B = None
        self.r: C = None
        self.txt = txt

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

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

d = A("d")
j = B("j")
g = C("g")
m = C("m")
l = A("l")
b = C("b")
k = C("k")
e = A("e")

d.o = m
d.r = m
d.q = j
j.o = l
j.w = d
g.x = d
m.x = d
l.o = g
l.r = g
l.q = j
b.x = e
k.x = l
e.o = b
e.r = b
e.q = j
assert g.x.r.x.o.x.r.x.o.txt == "m"