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

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

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

d = A("d")
m = B("m")
e = C("e")
f = B("f")
i = A("i")

d.r = f
m.u = f
m.r = i
e.v = i
e.t = i
e.s = d
f.u = m
f.r = d
i.r = m
assert i.r.u.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

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

d = A("d")
m = B("m")
e = C("e")
f = B("f")
i = A("i")

d.r = f
m.u = f
m.r = i
e.v = i
e.t = i
e.s = d
f.u = m
f.r = d
i.r = m
assert i.r.u.r.txt == "d"