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

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

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

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

i = A("i")
g = B("g")
k = C("k")
e = D("e")

i.q = e
g.x = e
g.p = e
g.w = i
k.o = g
e.q = g
assert e.q.w.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: D = None
        self.txt = txt

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

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

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

i = A("i")
g = B("g")
k = C("k")
e = D("e")

i.q = e
g.x = e
g.p = e
g.w = i
k.o = g
e.q = g
assert e.q.w.q.q.txt == "g"