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

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

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

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

b = A("b")
f = B("f")
e = C("e")
g = D("g")
c = C("c")

b.t = g
f.w = b
e.o = f
e.s = f
e.w = f
e.q = c
g.x = f
c.o = f
c.s = f
c.w = f
c.q = e
assert g.x.w.t.x.txt == "
class A:
    def __init__(self, txt: str):
        self.t: D = None
        self.txt = txt

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

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

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

b = A("b")
f = B("f")
e = C("e")
g = D("g")
c = C("c")

b.t = g
f.w = b
e.o = f
e.s = f
e.w = f
e.q = c
g.x = f
c.o = f
c.s = f
c.w = f
c.q = e
assert g.x.w.t.x.txt == "f"