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

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

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

m = A("m")
n = B("n")
g = C("g")
e = A("e")

m.r = n
n.u = g
g.r = n
e.r = n
assert m.r.u.r.u.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

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

m = A("m")
n = B("n")
g = C("g")
e = A("e")

m.r = n
n.u = g
g.r = n
e.r = n
assert m.r.u.r.u.txt == "g"