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

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

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

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

i = A("i")
d = B("d")
f = C("f")
a = D("a")
b = D("b")
k = C("k")

i.o = b
d.x = i
f.q = k
a.p = b
a.w = b
a.t = k
b.p = a
b.w = a
b.t = f
k.q = f
assert f.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.o: D = None
        self.txt = txt

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

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

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

i = A("i")
d = B("d")
f = C("f")
a = D("a")
b = D("b")
k = C("k")

i.o = b
d.x = i
f.q = k
a.p = b
a.w = b
a.t = k
b.p = a
b.w = a
b.t = f
k.q = f
assert f.q.q.q.txt == "k"