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

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

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

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

g.o = l
l.y = f
l.r = g
f.o = g
f.w = g
f.t = b
b.o = m
b.w = m
b.t = f
m.o = l
assert l.r.o.r.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

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

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

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

g.o = l
l.y = f
l.r = g
f.o = g
f.w = g
f.t = b
b.o = m
b.w = m
b.t = f
m.o = l
assert l.r.o.r.txt == "g"