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

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

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

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

f = A("f")
g = B("g")
c = C("c")
i = D("i")
n = B("n")

f.q = c
g.w = f
g.s = f
c.w = n
c.o = f
i.t = c
n.w = f
n.s = f
assert i.t.w.s.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.txt = txt

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

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

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

f = A("f")
g = B("g")
c = C("c")
i = D("i")
n = B("n")

f.q = c
g.w = f
g.s = f
c.w = n
c.o = f
i.t = c
n.w = f
n.s = f
assert i.t.w.s.txt == "f"