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

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

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

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

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

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

k.o = b
k.w = b
j.q = f
d.q = j
b.o = k
b.w = k
f.q = d
assert d.q.q.q.q.q.txt == "f"