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

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

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

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

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

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

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

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

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

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

a.v = h
a.u = c
b.s = e
e.q = h
e.w = h
e.x = j
c.x = b
h.x = b
j.v = h
j.u = c
assert b.s.x.u.x.s.txt == "e"