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

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

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

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

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

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

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

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

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

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

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