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

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

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

c = A("c")
j = B("j")
d = C("d")
e = A("e")
k = C("k")
f = A("f")
l = C("l")
b = B("b")

c.q = l
j.q = b
j.w = d
d.x = c
e.q = d
k.x = e
f.q = k
l.x = f
b.q = j
b.w = k
assert f.q.x.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.txt = txt

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

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

c = A("c")
j = B("j")
d = C("d")
e = A("e")
k = C("k")
f = A("f")
l = C("l")
b = B("b")

c.q = l
j.q = b
j.w = d
d.x = c
e.q = d
k.x = e
f.q = k
l.x = f
b.q = j
b.w = k
assert f.q.x.q.txt == "d"