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

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

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

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

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

g.t = l
g.r = j
b.q = g
j.v = b
l.w = j
l.o = g
l.q = b
l.v = b
assert b.q.r.v.txt == "
class A:
    def __init__(self, txt: str):
        self.t: D = None
        self.r: C = None
        self.txt = txt

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

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

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

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

g.t = l
g.r = j
b.q = g
j.v = b
l.w = j
l.o = g
l.q = b
l.v = b
assert b.q.r.v.txt == "b"