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

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

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

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

b = A("b")
h = B("h")
d = C("d")
g = D("g")

b.q = g
b.p = d
b.v = d
b.o = d
h.w = d
d.s = g
d.q = b
g.w = d
g.r = b
assert h.w.q.q.r.txt == "
class A:
    def __init__(self, txt: str):
        self.q: D = None
        self.p: C = None
        self.v: C = None
        self.o: C = None
        self.txt = txt

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

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

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

b = A("b")
h = B("h")
d = C("d")
g = D("g")

b.q = g
b.p = d
b.v = d
b.o = d
h.w = d
d.s = g
d.q = b
g.w = d
g.r = b
assert h.w.q.q.r.txt == "b"