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

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

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

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

a = A("a")
b = B("b")
h = C("h")
e = D("e")
m = D("m")
j = B("j")

a.s = h
a.u = h
b.r = j
b.w = j
h.q = j
h.v = a
e.u = b
m.u = b
j.r = b
j.w = b
assert h.q.w.r.w.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.u: C = None
        self.txt = txt

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

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

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

a = A("a")
b = B("b")
h = C("h")
e = D("e")
m = D("m")
j = B("j")

a.s = h
a.u = h
b.r = j
b.w = j
h.q = j
h.v = a
e.u = b
m.u = b
j.r = b
j.w = b
assert h.q.w.r.w.txt == "b"