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

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

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

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

i = A("i")
b = B("b")
c = C("c")
f = D("f")

i.q = b
b.o = c
c.o = f
c.x = i
f.t = c
f.u = c
assert c.x.q.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

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

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

i = A("i")
b = B("b")
c = C("c")
f = D("f")

i.q = b
b.o = c
c.o = f
c.x = i
f.t = c
f.u = c
assert c.x.q.o.o.txt == "f"