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

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

f = A("f")
a = B("a")
e = B("e")
k = B("k")
c = A("c")
j = A("j")

f.r = c
a.q = e
e.q = a
k.q = a
c.r = j
j.r = f
assert k.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.txt = txt

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

f = A("f")
a = B("a")
e = B("e")
k = B("k")
c = A("c")
j = A("j")

f.r = c
a.q = e
e.q = a
k.q = a
c.r = j
j.r = f
assert k.q.q.q.q.txt == "e"