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

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

m = A("m")
l = B("l")
k = B("k")
f = A("f")
j = B("j")
b = B("b")
d = A("d")

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

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

m = A("m")
l = B("l")
k = B("k")
f = A("f")
j = B("j")
b = B("b")
d = A("d")

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