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

class B:
    def __init__(self, txt: str):
        self.q: A = None
        self.s: A = None
        self.z: C = None
        self.x: D = None
        self.txt = txt

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

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

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

f.o = g
g.q = f
g.s = f
g.z = d
g.x = l
d.w = l
d.q = l
d.p = g
l.v = g
l.o = g
l.p = f
l.w = f
assert g.x.v.x.v.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.q: A = None
        self.s: A = None
        self.z: C = None
        self.x: D = None
        self.txt = txt

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

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

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

f.o = g
g.q = f
g.s = f
g.z = d
g.x = l
d.w = l
d.q = l
d.p = g
l.v = g
l.o = g
l.p = f
l.w = f
assert g.x.v.x.v.txt == "g"