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

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

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

f = A("f")
m = B("m")
g = C("g")
d = B("d")

f.v = d
m.t = g
m.v = f
m.w = d
g.r = m
d.t = g
d.v = f
d.w = m
assert d.v.v.t.r.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.txt = txt

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

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

f = A("f")
m = B("m")
g = C("g")
d = B("d")

f.v = d
m.t = g
m.v = f
m.w = d
g.r = m
d.t = g
d.v = f
d.w = m
assert d.v.v.t.r.txt == "m"