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

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

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

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

l = A("l")
g = B("g")
j = C("j")
f = D("f")

l.o = j
l.u = j
g.q = f
j.o = l
j.u = f
j.v = g
f.s = j
assert l.o.v.q.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.u: C = None
        self.txt = txt

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

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

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

l = A("l")
g = B("g")
j = C("j")
f = D("f")

l.o = j
l.u = j
g.q = f
j.o = l
j.u = f
j.v = g
f.s = j
assert l.o.v.q.txt == "f"