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

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

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

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

j = A("j")
h = B("h")
n = C("n")
f = D("f")
a = D("a")

j.q = n
j.s = h
h.q = f
n.u = j
n.w = h
f.t = h
f.q = h
f.u = a
a.t = h
a.q = h
a.u = f
assert j.s.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.s: B = None
        self.txt = txt

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

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

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

j = A("j")
h = B("h")
n = C("n")
f = D("f")
a = D("a")

j.q = n
j.s = h
h.q = f
n.u = j
n.w = h
f.t = h
f.q = h
f.u = a
a.t = h
a.q = h
a.u = f
assert j.s.q.q.q.txt == "f"