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

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

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

h = A("h")
c = B("c")
d = C("d")
m = A("m")

h.v = m
h.w = c
c.y = d
c.o = d
c.w = m
d.y = m
m.v = h
m.w = c
assert d.y.w.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.w: B = None
        self.txt = txt

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

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

h = A("h")
c = B("c")
d = C("d")
m = A("m")

h.v = m
h.w = c
c.y = d
c.o = d
c.w = m
d.y = m
m.v = h
m.w = c
assert d.y.w.y.y.txt == "m"