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

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

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

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

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

f.s = h
n.q = f
n.o = h
n.s = h
n.w = j
h.z = f
h.y = n
j.u = h
j.q = f
i.q = f
i.o = h
i.s = h
i.w = j
assert f.s.z.s.y.q.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.txt = txt

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

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

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

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

f.s = h
n.q = f
n.o = h
n.s = h
n.w = j
h.z = f
h.y = n
j.u = h
j.q = f
i.q = f
i.o = h
i.s = h
i.w = j
assert f.s.z.s.y.q.txt == "f"