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

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

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

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

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

b.r = j
e.o = j
e.v = j
e.p = b
e.s = g
j.t = b
g.t = b
g.r = j
assert j.t.r.t.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

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

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

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

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

b.r = j
e.o = j
e.v = j
e.p = b
e.s = g
j.t = b
g.t = b
g.r = j
assert j.t.r.t.txt == "b"