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

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

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

m = A("m")
g = B("g")
j = C("j")
e = B("e")
d = C("d")

m.o = d
g.t = m
g.r = j
j.t = d
e.t = m
e.r = d
d.t = j
assert g.r.t.t.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.txt = txt

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

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

m = A("m")
g = B("g")
j = C("j")
e = B("e")
d = C("d")

m.o = d
g.t = m
g.r = j
j.t = d
e.t = m
e.r = d
d.t = j
assert g.r.t.t.t.t.txt == "j"