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

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

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

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

h.x = k
j.w = g
j.v = a
f.w = g
f.x = a
a.w = f
a.v = j
k.x = h
m.x = k
g.w = f
g.x = a
assert k.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.txt = txt

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

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

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

h.x = k
j.w = g
j.v = a
f.w = g
f.x = a
a.w = f
a.v = j
k.x = h
m.x = k
g.w = f
g.x = a
assert k.x.x.x.txt == "h"