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

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

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

h = A("h")
a = B("a")
l = C("l")
g = A("g")
j = C("j")
k = A("k")

h.w = j
h.p = k
a.v = l
a.r = l
l.v = g
g.w = j
g.p = h
j.v = g
k.w = j
k.p = h
assert j.v.p.p.w.v.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.p: A = None
        self.txt = txt

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

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

h = A("h")
a = B("a")
l = C("l")
g = A("g")
j = C("j")
k = A("k")

h.w = j
h.p = k
a.v = l
a.r = l
l.v = g
g.w = j
g.p = h
j.v = g
k.w = j
k.p = h
assert j.v.p.p.w.v.w.txt == "j"