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

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

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

h = A("h")
b = B("b")
d = C("d")
i = B("i")

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

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

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

h = A("h")
b = B("b")
d = C("d")
i = B("i")

h.q = i
h.v = d
b.x = d
b.u = i
d.o = i
d.r = h
i.x = d
i.u = b
assert d.r.v.o.x.txt == "d"