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

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

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

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

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

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

d.o = i
d.w = j
j.q = l
l.q = j
e.o = d
e.w = c
c.q = j
i.o = f
i.w = l
k.o = f
k.w = c
f.o = d
f.w = j
assert j.q.q.q.q.txt == "j"