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

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

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

f = A("f")
m = B("m")
l = C("l")
a = A("a")
g = C("g")
b = A("b")

f.w = m
f.x = m
f.r = g
m.w = f
m.q = a
l.u = m
l.q = f
a.w = m
a.x = m
a.r = g
g.u = m
g.q = f
b.w = m
b.x = m
b.r = l
assert b.r.q.r.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.r: C = None
        self.x: B = None
        self.txt = txt

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

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

f = A("f")
m = B("m")
l = C("l")
a = A("a")
g = C("g")
b = A("b")

f.w = m
f.x = m
f.r = g
m.w = f
m.q = a
l.u = m
l.q = f
a.w = m
a.x = m
a.r = g
g.u = m
g.q = f
b.w = m
b.x = m
b.r = l
assert b.r.q.r.txt == "g"