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

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

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

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

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

h.r = d
m.y = h
m.u = b
d.u = h
d.r = m
b.v = h
b.q = h
b.o = h
b.w = m
assert b.o.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

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

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

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

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

h.r = d
m.y = h
m.u = b
d.u = h
d.r = m
b.v = h
b.q = h
b.o = h
b.w = m
assert b.o.r.r.txt == "m"