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

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

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

j = A("j")
g = B("g")
d = C("d")
m = A("m")
e = B("e")
l = C("l")
c = A("c")
f = B("f")
i = A("i")
b = A("b")

j.q = g
g.v = d
g.r = d
d.x = g
m.q = f
e.v = l
e.r = l
l.x = f
c.q = f
f.v = d
f.r = d
i.q = e
b.q = f
assert d.x.v.x.v.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

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

j = A("j")
g = B("g")
d = C("d")
m = A("m")
e = B("e")
l = C("l")
c = A("c")
f = B("f")
i = A("i")
b = A("b")

j.q = g
g.v = d
g.r = d
d.x = g
m.q = f
e.v = l
e.r = l
l.x = f
c.q = f
f.v = d
f.r = d
i.q = e
b.q = f
assert d.x.v.x.v.txt == "d"