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.t: B = None
        self.txt = txt

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

k.q = j
k.y = d
d.t = f
c.q = j
c.y = f
l.q = k
l.y = f
j.q = c
j.y = f
f.t = d
assert k.y.t.t.t.t.t.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.t: B = None
        self.txt = txt

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

k.q = j
k.y = d
d.t = f
c.q = j
c.y = f
l.q = k
l.y = f
j.q = c
j.y = f
f.t = d
assert k.y.t.t.t.t.t.txt == "f"