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.s: A = None
        self.txt = txt

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

b = A("b")
e = B("e")
c = C("c")
j = A("j")
n = A("n")
k = C("k")
g = A("g")
f = A("f")
h = A("h")
m = B("m")

b.x = j
e.w = k
e.s = n
c.s = m
c.y = e
j.x = f
n.x = g
k.s = e
k.y = m
g.x = b
f.x = j
h.x = b
m.w = k
m.s = b
assert j.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.s: A = None
        self.txt = txt

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

b = A("b")
e = B("e")
c = C("c")
j = A("j")
n = A("n")
k = C("k")
g = A("g")
f = A("f")
h = A("h")
m = B("m")

b.x = j
e.w = k
e.s = n
c.s = m
c.y = e
j.x = f
n.x = g
k.s = e
k.y = m
g.x = b
f.x = j
h.x = b
m.w = k
m.s = b
assert j.x.x.x.txt == "f"