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

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

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

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

j.r = m
j.o = n
a.o = m
l.w = n
l.r = b
l.o = a
n.o = j
m.r = j
m.o = a
b.w = a
b.o = a
b.r = l
assert j.o.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.o: B = None
        self.txt = txt

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

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

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

j.r = m
j.o = n
a.o = m
l.w = n
l.r = b
l.o = a
n.o = j
m.r = j
m.o = a
b.w = a
b.o = a
b.r = l
assert j.o.o.o.o.txt == "j"