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

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

i = A("i")
d = B("d")
k = A("k")
f = A("f")
c = B("c")
b = A("b")

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

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

i = A("i")
d = B("d")
k = A("k")
f = A("f")
c = B("c")
b = A("b")

i.q = b
i.y = d
d.o = c
k.q = f
k.y = d
f.q = b
f.y = c
c.o = d
b.q = f
b.y = c
assert d.o.o.o.o.o.txt == "c"