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

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

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

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

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

g.v = h
g.u = b
a.s = h
a.y = b
b.q = d
d.x = a
h.v = g
h.u = b
assert b.q.x.y.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.u: C = None
        self.txt = txt

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

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

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

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

g.v = h
g.u = b
a.s = h
a.y = b
b.q = d
d.x = a
h.v = g
h.u = b
assert b.q.x.y.txt == "b"