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

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

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

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

l = A("l")
i = B("i")
m = C("m")
b = D("b")

l.o = i
i.p = m
i.w = b
i.u = b
i.q = l
m.t = i
m.o = i
b.r = l
b.p = i
assert i.q.o.q.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

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

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

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

l = A("l")
i = B("i")
m = C("m")
b = D("b")

l.o = i
i.p = m
i.w = b
i.u = b
i.q = l
m.t = i
m.o = i
b.r = l
b.p = i
assert i.q.o.q.o.txt == "i"