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

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

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

b = A("b")
d = B("d")
m = C("m")
a = A("a")
f = A("f")
n = B("n")
j = B("j")

b.o = m
d.q = n
d.w = f
m.x = a
a.o = m
f.o = m
n.q = j
n.w = f
j.q = n
j.w = b
assert b.o.x.o.x.o.x.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.txt = txt

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

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

b = A("b")
d = B("d")
m = C("m")
a = A("a")
f = A("f")
n = B("n")
j = B("j")

b.o = m
d.q = n
d.w = f
m.x = a
a.o = m
f.o = m
n.q = j
n.w = f
j.q = n
j.w = b
assert b.o.x.o.x.o.x.txt == "a"