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

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

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

l = A("l")
m = B("m")
h = C("h")
a = C("a")
d = A("d")
c = B("c")

l.v = d
l.x = d
m.q = h
m.z = h
h.w = d
a.w = l
d.v = l
d.x = l
c.q = h
c.z = h
assert l.v.x.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.x: A = None
        self.txt = txt

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

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

l = A("l")
m = B("m")
h = C("h")
a = C("a")
d = A("d")
c = B("c")

l.v = d
l.x = d
m.q = h
m.z = h
h.w = d
a.w = l
d.v = l
d.x = l
c.q = h
c.z = h
assert l.v.x.v.txt == "d"