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

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

class C:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

g = A("g")
j = B("j")
b = C("b")
m = B("m")
n = A("n")

g.r = m
j.r = g
j.x = b
b.s = j
m.r = g
m.x = b
n.r = j
assert b.s.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

g = A("g")
j = B("j")
b = C("b")
m = B("m")
n = A("n")

g.r = m
j.r = g
j.x = b
b.s = j
m.r = g
m.x = b
n.r = j
assert b.s.r.r.txt == "m"