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

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

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

f = A("f")
i = B("i")
j = C("j")
m = B("m")
h = A("h")
k = B("k")
l = A("l")

f.w = i
f.v = l
i.r = j
i.q = h
i.p = m
j.p = f
j.o = i
m.r = j
m.q = f
m.p = k
h.w = m
h.v = f
k.r = j
k.q = f
k.p = m
l.w = k
l.v = h
assert m.q.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.v: A = None
        self.txt = txt

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

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

f = A("f")
i = B("i")
j = C("j")
m = B("m")
h = A("h")
k = B("k")
l = A("l")

f.w = i
f.v = l
i.r = j
i.q = h
i.p = m
j.p = f
j.o = i
m.r = j
m.q = f
m.p = k
h.w = m
h.v = f
k.r = j
k.q = f
k.p = m
l.w = k
l.v = h
assert m.q.v.v.txt == "h"