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

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

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

h = A("h")
j = B("j")
d = C("d")
g = B("g")
e = B("e")
m = A("m")

h.v = m
h.q = m
h.s = d
j.y = g
j.x = g
d.s = e
d.w = j
g.y = e
g.x = e
e.y = j
e.x = j
m.v = h
m.q = h
m.s = d
assert e.x.x.x.x.y.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.s: C = None
        self.q: A = None
        self.txt = txt

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

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

h = A("h")
j = B("j")
d = C("d")
g = B("g")
e = B("e")
m = A("m")

h.v = m
h.q = m
h.s = d
j.y = g
j.x = g
d.s = e
d.w = j
g.y = e
g.x = e
e.y = j
e.x = j
m.v = h
m.q = h
m.s = d
assert e.x.x.x.x.y.txt == "g"