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

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

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

m = A("m")
j = B("j")
g = C("g")
d = C("d")
a = A("a")
c = C("c")
f = A("f")
i = B("i")

m.w = i
j.u = f
j.q = f
g.q = d
d.q = c
a.w = i
c.q = d
f.w = j
i.u = m
i.q = m
assert f.w.q.w.u.w.q.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

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

m = A("m")
j = B("j")
g = C("g")
d = C("d")
a = A("a")
c = C("c")
f = A("f")
i = B("i")

m.w = i
j.u = f
j.q = f
g.q = d
d.q = c
a.w = i
c.q = d
f.w = j
i.u = m
i.q = m
assert f.w.q.w.u.w.q.txt == "f"